摘要: 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 n 阅读全文
posted @ 2012-11-25 20:53 chkkch 阅读(1671) 评论(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 longest 阅读全文
posted @ 2012-11-25 20:26 chkkch 阅读(2289) 评论(0) 推荐(0) 编辑
摘要: 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 use constant extra space.For example,Given the following binary tree, 1 / \ 2 3 / \ \ 4 5 ... 阅读全文
posted @ 2012-11-25 20:08 chkkch 阅读(1897) 评论(0) 推荐(0) 编辑
摘要: Givennnon-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,2,1,2,1], return6.The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of 阅读全文
posted @ 2012-11-25 19:26 chkkch 阅读(1127) 评论(0) 推荐(0) 编辑
摘要: Given an array withnobjects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.Note:You are not suppose to use the l 阅读全文
posted @ 2012-11-25 17:45 chkkch 阅读(2118) 评论(1) 推荐(0) 编辑
摘要: Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array. 1 class Solution { 2 public: 3 int findPos(int a[], int left, int right) 4 { 5 if (left ... 阅读全文
posted @ 2012-11-25 14:40 chkkch 阅读(775) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set toNULL.Initially, all next pointers are set toNULL.N... 阅读全文
posted @ 2012-11-25 14:13 chkkch 阅读(803) 评论(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 @ 2012-11-25 13:25 chkkch 阅读(993) 评论(0) 推荐(0) 编辑
摘要: Given a set ofnon-overlappingintervals, 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],[6,7],[8 阅读全文
posted @ 2012-11-25 12:10 chkkch 阅读(1518) 评论(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]. 1 /** 2 * Definition for an interval. 3 * struct Interval { 4 * int start; 5 * int end; 6 * Interval() : start(0), end(0) {} 7 * Interval(int... 阅读全文
posted @ 2012-11-25 11:53 chkkch 阅读(2117) 评论(0) 推荐(0) 编辑
摘要: Givennnon-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 ar 阅读全文
posted @ 2012-11-25 11:30 chkkch 阅读(1942) 评论(0) 推荐(0) 编辑
摘要: Givens1,s2,s3, find whethers3is formed by the interleaving ofs1ands2.For example,Given:s1="aabcc",s2="dbbca",Whens3="aadbbcbcac", return true.Whens3="aadbbbaccc", return false.DP. 1 class Solution { 2 private: 3 bool f[1000][1000]; 4 public: 5 bool isInterleav 阅读全文
posted @ 2012-11-25 10:46 chkkch 阅读(3732) 评论(4) 推荐(1) 编辑