摘要: Text JustificationApr 3 '12Given an array of words and a lengthL, format the text such that each line has exactlyLcharacters and is fully (left and right) justified.You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces' 'wh 阅读全文
posted @ 2013-03-04 17:47 西施豆腐渣 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Substring with Concatenation of All WordsFeb 24 '12You 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 without any intervening characters.For example, given:S:& 阅读全文
posted @ 2013-03-04 16:41 西施豆腐渣 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Sort ColorsApr 9 '12Given 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 阅读全文
posted @ 2013-03-04 15:09 西施豆腐渣 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Simplify PathApr 4 '12Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"Corner Cases:Did you consider the case wherepath="/../"?In this case, you should return" 阅读全文
posted @ 2013-03-04 13:29 西施豆腐渣 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Search Insert PositionMar 3 '12Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here are few examples.[1,3,5,6], 5 → 2[1,3,5,6], 2 → 1[1,3,5,6], 7 → 阅读全文
posted @ 2013-03-04 12:05 西施豆腐渣 阅读(143) 评论(0) 推荐(0) 编辑
摘要: Search in Rotated Sorted Array IIApr 20 '12Follow 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.the time complexity is O(n). this is a example u 阅读全文
posted @ 2013-03-04 11:45 西施豆腐渣 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Search in Rotated Sorted ArrayMar 3 '12Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in 阅读全文
posted @ 2013-03-04 09:25 西施豆腐渣 阅读(113) 评论(0) 推荐(0) 编辑