上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 25 下一页
摘要: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and "([)]&qu 阅读全文
posted @ 2013-06-05 09:55 冰点猎手 阅读(135) 评论(0) 推荐(0)
摘要: 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 number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0.For example, given n = 2, return [0,1,3,2]. Its gray c 阅读全文
posted @ 2013-06-05 00:05 冰点猎手 阅读(151) 评论(0) 推荐(0)
摘要: 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 read off as "one 2, then one 1" or 1211.Given an integer n, generate the nth sequence.Note: The 阅读全文
posted @ 2013-05-25 00:09 冰点猎手 阅读(149) 评论(0) 推荐(0)
摘要: 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 should run in O(n) time and uses constant space.技巧性比较强:参考: http://blog.unieagle.net/2012/09/20/leetcode%E9%A2%98%E7%9B%AE%EF%BC%9Afirst-missing-positive/ 阅读全文
posted @ 2013-05-24 23:36 冰点猎手 阅读(152) 评论(0) 推荐(0)
摘要: Given a number represented as an array of digits, plus one to the number. class Solution {public: vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function int n = digits.size(); digits[n-1]++; for(... 阅读全文
posted @ 2013-05-23 23:56 冰点猎手 阅读(122) 评论(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-05-23 23:00 冰点猎手 阅读(215) 评论(0) 推荐(0)
摘要: 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,−1,2,1] has the largest sum = 6. DP : B[i]为以A[i]节点作为截止节点的subarray的the largest sum,那么B[i] = max (A[i], B[i-1] + A[i]. 阅读全文
posted @ 2013-05-23 22:11 冰点猎手 阅读(133) 评论(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. class Solution {public: int maximalRectangle(vector<vector<char> > &matrix) { // Start typing your C/C++ solution below // DO NOT write int main() function .. 阅读全文
posted @ 2013-05-23 21:58 冰点猎手 阅读(257) 评论(0) 推荐(0)
摘要: 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 histogram.Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3].The largest rectangle is shown in the shaded area, which has 阅读全文
posted @ 2013-05-23 16:41 冰点猎手 阅读(475) 评论(0) 推荐(0)
摘要: Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case. class Solution {private: vector<string> result; map<string, vector<string>> m;public: vector<string> anagrams(vector<string> &strs) { // Start typing yo 阅读全文
posted @ 2013-05-07 22:28 冰点猎手 阅读(150) 评论(0) 推荐(0)
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 25 下一页