摘要: 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)