摘要:Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After ...
阅读全文
摘要: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 linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, ...
阅读全文
摘要:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array A = [1,1,1,2,2,3],Your function should r...
阅读全文
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for...
阅读全文
摘要:Implement pow(x, n).» Solve this problem[解题思路]二分法,注意n<0的情况。[Code]1: double power(double x, int n) 2: { 3: if (n == 0) 4: return...
阅读全文
摘要:Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is ...
阅读全文
摘要:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil...
阅读全文
摘要:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointe...
阅读全文
摘要:Given a number represented as an array of digits, plus one to the number.» Solve this problem[解题思路]加位与进位。模拟。[Code]1: vector plusOne(vector &digits) {...
阅读全文
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique per...
阅读全文
摘要:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1]...
阅读全文
摘要:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum ...
阅读全文
摘要:Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].[ [1], [1,1], [1,2,1], [1,3,3,1], [1...
阅读全文
摘要:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the o...
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinki...
阅读全文
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl...
阅读全文
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-nega...
阅读全文
摘要:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODE...
阅读全文
摘要:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.N...
阅读全文
摘要: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...
阅读全文
摘要:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space to hold additional elements fr...
阅读全文
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.» Solve this problem[解题思路]merge sort。外面套一层循环即可。注意指针操...
阅读全文
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be ...
阅读全文
摘要:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1...
阅读全文
摘要: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 string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo...
阅读全文
摘要:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longes...
阅读全文
摘要:Write a function to find the longest common prefix string amongst an array of strings.» Solve this problem[解题报告]又一个实现题。遍历字符串数组,每次用当前prefix和下一个字符串匹配以生成...
阅读全文
摘要:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephon...
阅读全文
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word ...
阅读全文
摘要:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the hist...
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu...
阅读全文
摘要:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximu...
阅读全文
摘要:Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", retur...
阅读全文
摘要:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.» Solve this problem[解题思路]这道题主要就在于如何处理每一位dig...
阅读全文
摘要:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initial...
阅读全文
摘要:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.» Solve this problem[解题思...
阅读全文
摘要:The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total numb...
阅读全文
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((...
阅读全文
摘要:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t...
阅读全文
摘要:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm sho...
阅读全文
摘要:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have t...
阅读全文
摘要:Divide two integers without using multiplication, division and mod operator.两个数的除法,但是不允许用乘、除、取余符号。[解题思路]如果可以用乘的话,二分搜索倒是不错的解法。否则,只能寄希望于位符操作了。 基本思想就是把除数...
阅读全文
摘要:Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from th...
阅读全文