上一页 1 2 3 4 5 6 7 8 ··· 17 下一页
摘要: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences. For example, givens = "catsanddog",dict = ["cat", "cats", "and", "sand", "dog 阅读全文
posted @ 2013-10-06 23:10 懒猫欣 阅读(914) 评论(0) 推荐(0)
摘要: 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 = "aadbbbaccc", return false.动态规划,前i个s1和前j个s2能否组成前i+jclass Solution {public: bool isInterleave 阅读全文
posted @ 2013-10-06 22:13 懒猫欣 阅读(160) 评论(0) 推荐(0)
摘要: 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 window is "BANC".Note:If there is no such window in S that covers all characters in T, return the 阅读全文
posted @ 2013-10-06 20:51 懒猫欣 阅读(190) 评论(0) 推荐(0)
摘要: 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 times. Example 1:Given intervals [1,3],[6,9], insert and merge [2,5] in as [1,5],[6,9].Example 2:Given [1,2],[3,5], 阅读全文
posted @ 2013-10-06 20:13 懒猫欣 阅读(167) 评论(0) 推荐(0)
摘要: 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].class Solution { struct IntvTreeNode{ int start; int end; int max; IntvTreeNode* left; IntvTreeNode* right; IntvTree... 阅读全文
posted @ 2013-10-06 19:10 懒猫欣 阅读(150) 评论(0) 推荐(0)
摘要: 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 "()", which has length = 2.Another example is ")()())", where the lo 阅读全文
posted @ 2013-10-06 15:58 懒猫欣 阅读(161) 评论(0) 推荐(0)
摘要: Divide two integers without using multiplication, division and mod operator.思路是使用人做除法时的运算式 每次取前除数长度或加1位还原成数字,做减法求出该位的商,需要注意很多特殊情况。。class Solution {public: //a/b void Sub(string& a,string& b,string&ret,long long ib,stringstream& ss){ int i=0; string a1; bool all=false; ... 阅读全文
posted @ 2013-10-06 15:06 懒猫欣 阅读(170) 评论(0) 推荐(0)
摘要: 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 possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate extra memory.He 阅读全文
posted @ 2013-10-06 11:13 懒猫欣 阅读(173) 评论(0) 推荐(0)
摘要: 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 maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps. For example:Given array A = [2,3,1,1,4]The minimum 阅读全文
posted @ 2013-10-06 10:46 懒猫欣 阅读(107) 评论(0) 推荐(0)
摘要: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.应用直方图找矩形的函数 将每一行每一位上方的1的个数化为直方图,面积最大的矩形即都为1且面积最大的矩形class Solution {public: int largestRectangleArea(vector &height) { if(height.size()==0)return 0; stack > sta; ... 阅读全文
posted @ 2013-10-06 02:20 懒猫欣 阅读(205) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 ··· 17 下一页