- 博客(73)
- 资源 (1)
- 收藏
- 关注
原创 LeetCode | Trapping Rain Water
题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3
2013-12-31 16:35:53 3578
原创 LeetCode | Substring with Concatenation of All Words
题目:You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and w
2013-12-31 16:17:07 3734
原创 LeetCode| Scramble String
题目:Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great /
2013-12-31 15:24:51 3938
原创 LeetCode | Longest Valid Parentheses
题目:Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is
2013-12-31 13:56:13 2101
原创 LeetCode | Text Justification
题目:Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.You should pack your words in a greedy app
2013-12-27 01:00:14 2086 1
原创 LeetCode | Count and Say
题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is rea
2013-12-26 23:02:28 2271 3
原创 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 in th
2013-12-26 22:45:34 2235
原创 LeetCode | Combination Sum
题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlim
2013-12-26 22:34:28 2222
原创 leetCode | Next Permutation
题目:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest
2013-12-26 22:14:05 4761
原创 LeetCode | Divide Two Integers
题目:Divide two integers without using multiplication, division and mod operator.思路:1)考虑边界问题。2)考虑INT_MIN与INT_MAX绝对值之间差1。3)考虑符号。类似http://blog.csdn.net/lanxu_yy/article/details/11686
2013-12-26 21:32:32 2055
原创 LeetCode | String to Integer (atoi)
题目:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible
2013-12-26 20:50:39 1936
原创 LeetCode | Word Ladder
题目:Given two words (start and end), and a dictionary, find the length of shortest transformation sequence fromstart to end, such that:Only one letter can be changed at a timeEach intermediat
2013-12-26 17:52:39 1958 1
原创 LeetCode | Implement strStr()
题目:Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.思路:BF或者KMP算法。BF无法通过时间复杂度要求。代码:class S
2013-12-26 14:24:03 2669
原创 LeetCode | Minimum Window Substring
题目: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 = "ADOBECODEBANC"T = "ABC"Minimum windo
2013-12-26 12:43:54 1688 3
原创 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.思路:模拟乘法的过程。首先第二个数的每一
2013-12-25 17:07:03 1401
原创 LeetCode | Merge Intervals
题目:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].思路:首先按照start来排序,然后依次合并相邻的重叠项。
2013-12-25 16:43:17 1455
原创 LeetCode | Insert Interval
题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start ti
2013-12-25 16:15:46 1499
原创 LeetCode | Distinct Subsequences
题目: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 the original string by deleting some (c
2013-12-25 13:00:51 2752
原创 LeetCode | Maximal Rectangle
题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.思路:基本思路是循环确定一个左上角的点与右下角的点,然后判断该区域是否都为’1‘。如下图:为了循环利用,我们可以采用动态
2013-12-24 17:32:55 5754
原创 LeetCode | Spiral Matrix II
题目:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9
2013-12-24 14:26:04 1426
原创 LeetCode | Spiral Matrix
题目:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9
2013-12-24 14:15:25 1844
原创 LeetCode | Maximum Subarray
题目: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,−5,4],the contiguous subarray [4,−
2013-12-24 13:12:34 3401 1
原创 LeetCode | Combinations
题目:Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3],
2013-12-24 11:32:20 1352
原创 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], and
2013-12-24 11:07:35 1111
原创 LeetCode | Permutations
题目: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], [3,1,2], and [3,2,1].
2013-12-24 10:47:09 1484
原创 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 example:Give
2013-12-24 10:39:51 1464
原创 LeetCode | ZigZag Conversion
题目: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 for better legibility)P A H NA
2013-12-24 10:23:40 1975 2
原创 LeetCode | Unique Paths II
题目:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively
2013-12-23 18:25:41 1591
原创 LeetCode | Unique Paths
题目: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
2013-12-23 18:21:01 1219
原创 LeetCode | Interleaving String
题目: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", return true.When s3 = "aadbbba
2013-12-23 18:08:55 1304
原创 LeetCode | Unique Binary Search Trees II
题目:Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1
2013-12-23 14:58:40 10864
原创 LeetCode | Unique Binary Search Trees
题目:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2
2013-12-23 14:17:49 3695
原创 LeetCode | Generate Parentheses
题目: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:"((()))", "(()())", "(())()", "()(()
2013-12-23 13:41:51 1070 1
原创 LeetCode | Simplify Path
题目:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:
2013-12-23 12:15:09 1233
原创 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 down or
2013-12-23 10:59:03 2207
原创 LeetCode | Rotate Image
题目:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:将matrix中的结点考虑为空间向量。顺时针转动90度就是每个
2013-12-23 10:06:00 4804 2
原创 LeetCode | Single Number II
题目:Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it wi
2013-12-20 11:18:07 5061 7
原创 LeetCode | Construct Binary Tree from Preorder and Inorder Traversal
题目:Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.思路:与http://blog.csdn.net/lanxu_yy/arti
2013-12-17 20:32:14 1038
原创 LeetCode | Construct Binary Tree from Inorder and Postorder 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.思路:postorder的最后一位始终是子树的
2013-12-17 20:26:08 1094
原创 LeetCode | Anagrams
题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.思路:判断两个字符串是否为anagram的方法可以有:1)将每个字符串的所有字符按字典序排列,比较是否相同。2)用H
2013-12-17 13:29:34 1793 3
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人