上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页

2013年7月16日

摘要: Problem:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5,7], [4,1,8,3]]The minimum path sum from top to bottom is11(i.e.,2+3+5+1= 11).Note:Bonus point if y... 阅读全文
posted @ 2013-07-16 01:25 freeneng 阅读(185) 评论(0) 推荐(0) 编辑

2013年5月26日

摘要: Problem:Given a set of distinct integers,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,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]Analysis:Simple backt... 阅读全文
posted @ 2013-05-26 14:58 freeneng 阅读(169) 评论(0) 推荐(0) 编辑
摘要: Problem:Given two integersnandk, return all possible combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]Analysis:Simple backtracking problem.Code: 1 class Solution { 2 public: 3 vector<vector<int> > res; 4 int kk;.. 阅读全文
posted @ 2013-05-26 14:23 freeneng 阅读(149) 评论(0) 推荐(0) 编辑
摘要: Problem:Write 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 matrix:[ [. 阅读全文
posted @ 2013-05-26 13:43 freeneng 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Problem:Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.Follow up:Did you use extra space?A straight forward solution using O(mn) space is probably a bad idea.A simple improvement uses O(m+n) space, but still not the best solution.Could you devise a constant 阅读全文
posted @ 2013-05-26 13:09 freeneng 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Problem:Given 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"/".Another c 阅读全文
posted @ 2013-05-26 12:33 freeneng 阅读(202) 评论(0) 推荐(0) 编辑
摘要: Problem:Given amxngrid filled with non-negative numbers, find a path from top left to bottom right whichminimizesthe sum of all numbers along its path.Note:You can only move either down or right at any point in time.Analysis:Simple DP problem, always choose the minimum path preceed the current posit 阅读全文
posted @ 2013-05-26 12:05 freeneng 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Problem:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as1and0respectively in the grid.For example,There is one obstacle in the middle of a 3x3 grid as illustrated below.[ [0,0,0 阅读全文
posted @ 2013-05-26 11:56 freeneng 阅读(112) 评论(0) 推荐(0) 编辑
摘要: Problem:Given a list, rotate the list to the right bykplaces, wherekis non-negative.For example:Given1->2->3->4->5->NULLandk=2,return4->5->1->2->3->NULL.Analysis:The first thought is to use the same strategy as in "Remove Kth Node in List" -- using two pointer 阅读全文
posted @ 2013-05-26 11:38 freeneng 阅读(201) 评论(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.Determine if you are able to reach the last index.For example:A =[2,3,1,1,4], returntrue.A =[3,2,1,0,4], return 阅读全文
posted @ 2013-05-26 08:00 freeneng 阅读(120) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页

导航