- 博客(89)
- 收藏
- 关注
原创 [Leetcode] Sort List
题目:Sort a linked list in O(n log n) time using constant space complexity.思路:O(nlogn)的sort有quick sort, merge sort, heap sort. 首先排除heap sort, heap需要用到O(n)的空间。其次排除quick sort,
2014-11-30 10:14:54
263
原创 [Leetcode] Next Permutation
题目:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end shoul
2014-11-13 09:56:00
294
原创 [Leetcode] Reverse Nodes in k-Group
题目:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and
2014-11-10 06:27:06
261
原创 [Leetcode] Container With Most Water
题目:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of co
2014-11-10 05:05:34
250
原创 [Leetcode] Palindrome Number
题目:Determine whether an integer is a palindrome. Do this without extra space.click to show spoilers.Some hints:Could negative integers be palindromes? (ie, -1)If you are thinking of co
2014-11-10 04:54:59
243
原创 [Leetcode] Longest Palindromic Substring
题目: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 longest palindromic substring.思路:
2014-11-10 04:41:49
214
原创 [Leetcode] Permutations II
题目:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1],
2014-11-06 14:05:23
280
原创 [Leetcode] Minimum Window Substring
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is
2014-11-06 11:43:27
372
原创 [Leetcode] Longest Substring Without Repeating Characters
题目:Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which
2014-11-06 10:36:59
210
原创 [Leetcode] Palindrome Partitioning II
题目:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X
2014-11-01 04:29:12
234
原创 [Leetcode] Surrounded Regions
题目:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is
2014-10-27 11:07:50
322
原创 [Leetcode] Longest Consecutive Sequence
题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like:
2014-10-24 10:33:58
235
原创 [Leetcode] Populating Next Right Pointers in Each Node II
题目: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 still work?Note:You may only
2014-10-22 12:15:35
244
原创 [Leetcode] Populating Next Right Pointers in Each Node
题目:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next
2014-10-22 11:28:39
234
原创 [Leetcode] Flatten Binary Tree to Linked List
题目:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should loo
2014-10-22 11:13:01
236
原创 [Leetcode] Path Sum II
题目: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 = 22, 5
2014-10-22 10:54:13
233
原创 [Leetcode] Path Sum
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:类似二分法,中间向左右两边找child.class Solution {public: int tr
2014-10-22 10:49:00
211
原创 [Leetcode] Convert Sorted List to Binary Search Tree
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.思路:类似二分法,中间向左右两边找child.class Solution {public: TreeNo
2014-10-22 10:31:40
266
原创 [Leetcode] Convert Sorted Array to Binary Search Tree
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:in order遍历后的数组为[left_tree, r
2014-10-22 10:20:34
214
原创 [Leetcode] Construct Binary Tree from Preorder and Inorder Traversal
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:in order遍历后的数组为[left_tree, r
2014-10-22 10:04:45
280
原创 [Leetcode] Construct Binary Tree from Inorder and Postorder Traversal
题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:
2014-10-22 09:39:48
220
原创 [Leetcode] Binary Tree Zigzag Level Order Traversal
题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For ex
2014-10-21 05:06:35
247
原创 [Leetcode] Restore IP Addresses
题目:Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.
2014-10-21 04:30:46
214
原创 [Leetcode] Partition List
题目: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 original relative order of the nod
2014-10-21 04:05:37
209
原创 [Leetcode] Remove Duplicates from Sorted List II
题目: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, return 1->2->3.思路:两个指
2014-10-21 03:49:03
488
原创 [Leetcode] Remove Duplicates from Sorted List
题目: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, return 1->2->3.
2014-10-21 03:21:55
227
原创 [Leetcode] Search in Rotated Sorted Array II
题目:Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given tar
2014-10-21 03:07:54
232
原创 [Leetcode] Search a 2D Matrix
题目:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The fi
2014-10-21 02:49:00
202
原创 [Leetcode] Edit Distance
题目: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 the following 3 operations per
2014-10-21 02:31:20
223
原创 [Leetcode] Minimum Path Sum
题目: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.Note: You can only move either
2014-10-21 00:39:57
228
原创 [Leetcode] Unique Paths II
题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to r
2014-10-21 00:24:38
200
原创 [Leetcode] Unique Paths
题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路:回溯法,和N-Queens I基本一样。class Solution {
2014-10-21 00:09:52
204
原创 [Leetcode] Maximum Subarray
题目:Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.思路:回溯法,和N-Queens I基本一样。class Solution {
2014-10-20 11:25:01
239
原创 [Leetcode] N-Queens II
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-
2014-10-20 07:07:58
208
原创 [Leetcode] N-Queens
题目:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutio
2014-10-20 05:36:20
199
原创 [Leetcode] Multiply Strings
题目:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.思路:递归寻找所有可能。
2014-10-20 01:56:00
213
原创 [Leetcode] Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once
2014-10-18 09:49:30
186
原创 [Leetcode] Combination Sum
题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the t
2014-10-18 09:36:30
224
原创 [Leetcode] Search for a Range
题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in
2014-10-18 05:39:10
228
原创 [Leetcode] Search in Rotated Sorted Array
题目:Divide two integers without using multiplication, division and mod operator.思路:D = a0 * d * 2^n + a1 * d * 2^(n-1) + ... + an * d * 2^0,从d * 2^n开始,不断的用被除数减去这个值,同时计算ai.最终
2014-10-18 04:59:27
215
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人