08 2015 档案
摘要:百度:1.从键盘输入一个字符串,长度未知,然后输出所有的全排列。例如输入abc, 输出abc,acb,bac,bca,cab,cba这样。很遗憾,当时思路不清晰,说了半天没说出个所以然。不知道这种题目对于大家来说是不是很简单,一下就做出来了。2.生日悖论问题。不知道自己去百度吧。这个问题其实很简单的...
阅读全文
摘要:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.Solution 1: recursionruntime: 28ms./** * ...
阅读全文
摘要:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-...
阅读全文
摘要:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Hide Tags:Linked ListTwo PointersHide Simi...
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?Sol...
阅读全文
摘要:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth...
阅读全文
摘要:Given a non-negative integernum, repeatedly add all its digits until the result has only one digit.For example:Givennum = 38, the process is like:3 + ...
阅读全文
摘要:Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->...
阅读全文
摘要:Given a binary tree, return thebottom-up level ordertraversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For exa...
阅读全文
摘要:Given a binary tree, return thelevel ordertraversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree{3,9,2...
阅读全文
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
阅读全文
摘要:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le...
阅读全文
摘要:Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.(http://sudoku.com.au/TheRules.aspx)The Sudoku board could be partially filled...
阅读全文
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.Note:You may assume thatnums1has enough space (size that is great...
阅读全文
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Solution: 1 class Solution...
阅读全文
摘要:Given a stringsand a dictionary of wordsdict, determine ifscan be segmented into a space-separated sequence of one or more dictionary words.For exampl...
阅读全文
摘要:Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr...
阅读全文
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1...
阅读全文
摘要:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ ...
阅读全文
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an...
阅读全文
摘要:118 - Pascal's TriangleGivennumRows, generate the firstnumRowsof Pascal's triangle.For example, givennumRows= 5,Return[ [1], [1,1], [1,2,1], ...
阅读全文
摘要:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1is read off as"one 1"or11.11is read off as"tw...
阅读全文
摘要:Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After re...
阅读全文
摘要:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, retu...
阅读全文
摘要:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't mat...
阅读全文
摘要:Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for a...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings.Solution: 1 class Solution { 2 public: 3 string longestCommo...
阅读全文
摘要:Compare two version numbersversion1andversion2.Ifversion1>version2return 1, ifversion1sum2)return 1;16 else if(sum1<sum2)return -1;17 ...
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes...
阅读全文
摘要:12- Integer to RomanGiven an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.Solution: 枚举,考虑每个字符以及每两个...
阅读全文
摘要:66 - Plus OneGiven a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significan...
阅读全文
摘要:168 - Excel Sheet Column TitleGiven a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 ...
阅读全文
摘要:Given an integern, return the number of trailing zeroes inn!.Note:Your solution should be in logarithmic time complexity.Solution :计算包含的2和5组成的pair的个数,...
阅读全文
摘要:Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come...
阅读全文
摘要:190 - Reverse BitsReverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010000011110...
阅读全文
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo...
阅读全文
摘要:Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer...
阅读全文
摘要:The string"PAYPALISHIRING"is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font fo...
阅读全文
摘要:Find the total area covered by tworectilinearrectangles in a2Dplane.Each rectangle is defined by its bottom left corner and top right corner as shown ...
阅读全文
摘要:217 - Contains DuplicateGiven an array of integers, find if the array contains any duplicates. Your function should return true if any value appears a...
阅读全文
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9 to 4 / \ 7 2 / \ / \9 6 3 1Notice:Google: 90% of our engineers...
阅读全文
摘要:Given two stringssandt, write a function to determine iftis an anagram ofs.For example,s= "anagram",t= "nagaram", return true.s= "rat",t= "car", retur...
阅读全文
摘要:232 - Implement Queue using StacksImplement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- R...
阅读全文

浙公网安备 33010602011771号