上一页 1 ··· 39 40 41 42 43 44 45 46 47 ··· 51 下一页
2013年12月26日
摘要: Subsets2013.12.26 15:19Given 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], []]Soluti... 阅读全文
posted @ 2013-12-26 15:22 zhuli19901106 阅读(891) 评论(0) 推荐(0) 编辑
2013年12月22日
摘要: Combinations2013.12.22 05:17Given 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],]Solution: Combination and permutation problems are usually solved with DFS recursion. When solv... 阅读全文
posted @ 2013-12-22 05:52 zhuli19901106 阅读(249) 评论(0) 推荐(0) 编辑
摘要: Sort Colors2013.12.22 04:39Given 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 a 阅读全文
posted @ 2013-12-22 04:42 zhuli19901106 阅读(193) 评论(0) 推荐(0) 编辑
摘要: Search a 2D Matrix2013.12.22 04:30Write 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 阅读全文
posted @ 2013-12-22 04:31 zhuli19901106 阅读(208) 评论(0) 推荐(0) 编辑
摘要: Simplify Path2013.12.22 04:19Given an absolute path for a file (Unix-style), simplify it.For example,path="/home/", =>"/home"path="/a/./b/../../c/", =>"/c"click to show corner cases.Corner Cases:Did you consider the case wherepath="/../"?In thi 阅读全文
posted @ 2013-12-22 04:20 zhuli19901106 阅读(193) 评论(0) 推荐(0) 编辑
摘要: Climbing Stairs2013.12.22 04:13You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Solution: Search for "Fibonacci sequence" and calculate the nth element in the sequence. Time com 阅读全文
posted @ 2013-12-22 04:16 zhuli19901106 阅读(226) 评论(0) 推荐(0) 编辑
摘要: Sqrt(x)2013.12.22 04:02Implementint sqrt(int x).Compute and return the square root ofx.Solution 1: The square root can be calculated using a binary iteration, with an initial interval of [1, x - 1]. Time complexity is O(log2(x)), space complexity is O(1).Accepted code: 1 // 2WA, 1AC, binary search.. 阅读全文
posted @ 2013-12-22 04:05 zhuli19901106 阅读(279) 评论(0) 推荐(0) 编辑
摘要: Plus One2013.12.22 03:37Given a number represented as an array of digits, plus one to the number.Solution: This problem seems quite easy, right? See if you can AC with one shot. Here're some good test cases for you: 0 + 1 = 1 1 + 1 = 2 34 + 1 = 35 99 + 1 = 100 Note that we write the n... 阅读全文
posted @ 2013-12-22 03:44 zhuli19901106 阅读(238) 评论(0) 推荐(0) 编辑
摘要: Add Binary2013.12.22 03:31Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".Solution: This is a problem about big integer addition, only in that it's binary. My solution is to add them up bit by bit, reverse the c 阅读全文
posted @ 2013-12-22 03:36 zhuli19901106 阅读(295) 评论(0) 推荐(0) 编辑
摘要: Merge Two Sorted Lists2013.12.22 03:24Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Solution: This is a FAQ in IT interview. Make sure you don't new any node, and watch out for any special cases like N 阅读全文
posted @ 2013-12-22 03:30 zhuli19901106 阅读(171) 评论(0) 推荐(0) 编辑
上一页 1 ··· 39 40 41 42 43 44 45 46 47 ··· 51 下一页