2013年8月19日

摘要: Two SumGiven an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index 阅读全文
posted @ 2013-08-19 23:24 似溦若岚 阅读(163) 评论(0) 推荐(0) 编辑
摘要: Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given[100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is[1, 2, 3, 4]. Return its length:4.Your algorithm should run in O(n) complexity.用unordered_ 阅读全文
posted @ 2013-08-19 22:52 似溦若岚 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Sum Root to Leaf NumbersGiven a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path1->2r 阅读全文
posted @ 2013-08-19 19:15 似溦若岚 阅读(156) 评论(0) 推荐(0) 编辑
摘要: Surrounded RegionsGiven a 2D board containing'X'and'O', capture all regions surrounded by'X'.A region is captured by flipping all'O's into'X's in that surrounded region .For example,X X X XX O O XX X O XX O X XAfter running your function, the board should be:X 阅读全文
posted @ 2013-08-19 18:29 似溦若岚 阅读(155) 评论(0) 推荐(0) 编辑
摘要: Palindrome PartitioningGiven a strings, partitionssuch that every substring of the partition is a palindrome.Return all possible palindrome partitioning ofs.For example, givens="aab",Return [ ["aa","b"], ["a","a","b"] ]历遍的说…… 1 class Soluti 阅读全文
posted @ 2013-08-19 13:56 似溦若岚 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Search a 2D MatrixWrite an efficient algorithm that searches for a value in anmxnmatrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.For example,Consider the following m 阅读全文
posted @ 2013-08-19 12:54 似溦若岚 阅读(141) 评论(0) 推荐(0) 编辑
摘要: Sort ColorsGiven 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 t 阅读全文
posted @ 2013-08-19 11:23 似溦若岚 阅读(145) 评论(0) 推荐(0) 编辑

导航