2013年8月17日

摘要: Problem:Given 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 X X XX X 阅读全文
posted @ 2013-08-17 03:35 freeneng 阅读(228) 评论(0) 推荐(0) 编辑

2013年8月11日

摘要: Problem:Given a collection of integers that might contain duplicates,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,IfS=[1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]Analysi... 阅读全文
posted @ 2013-08-11 14:09 freeneng 阅读(276) 评论(0) 推荐(0) 编辑

2013年8月9日

摘要: Problem:Given 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"] ]Analysis:At first glance, it seems v 阅读全文
posted @ 2013-08-09 12:11 freeneng 阅读(217) 评论(0) 推荐(0) 编辑
摘要: Problem:Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be only one unique solution.A sudoku puzzle......and its solution numbers marked in red.Analysis:The basic dfs problem. Notice the structur 阅读全文
posted @ 2013-08-09 10:45 freeneng 阅读(184) 评论(0) 推荐(0) 编辑

2013年8月7日

摘要: Problem:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2]have the following unique permutations:[1,1,2],[1,2,1], and[2,1,1].Analysis:An normal way to solve the problem is first generate all the possible permutations, and then com 阅读全文
posted @ 2013-08-07 07:10 freeneng 阅读(244) 评论(0) 推荐(0) 编辑
摘要: Problem: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 m 阅读全文
posted @ 2013-08-07 06:06 freeneng 阅读(245) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, � ,a 阅读全文
posted @ 2013-08-07 05:06 freeneng 阅读(161) 评论(0) 推荐(0) 编辑

2013年8月6日

摘要: Problem:Given a matrix ofmxnelements (mrows,ncolumns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]You should return[1,2,3,6,9,8,7,4,5].Analysis:The problem is a simulation problem. With the help of a direction vari 阅读全文
posted @ 2013-08-06 15:14 freeneng 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Problem: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 u 阅读全文
posted @ 2013-08-06 14:41 freeneng 阅读(181) 评论(0) 推荐(0) 编辑
摘要: Problem:Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.Analysis:At first thought, hash table can be used in this problem. First hash all the numbers in the giv 阅读全文
posted @ 2013-08-06 13:04 freeneng 阅读(171) 评论(0) 推荐(0) 编辑

导航