摘要: Implementint sqrt(int x).Compute and return the square root ofx.题解:二分的方法,从0,1,2.....x搜索sqrt(x)的值。代码如下: 1 public class Solution { 2 public int sqrt... 阅读全文
posted @ 2014-07-18 16:02 SunshineAtNoon 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest le... 阅读全文
posted @ 2014-07-18 15:29 SunshineAtNoon 阅读(135) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened t... 阅读全文
posted @ 2014-07-18 15:18 SunshineAtNoon 阅读(258) 评论(0) 推荐(0) 编辑
摘要: Given an indexk, return thekthrow of the Pascal's triangle.For example, givenk= 3,Return[1,3,3,1].Note:Could you optimize your algorithm to use onlyO(... 阅读全文
posted @ 2014-07-18 15:00 SunshineAtNoon 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Given 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 ... 阅读全文
posted @ 2014-07-18 14:40 SunshineAtNoon 阅读(228) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.Fo... 阅读全文
posted @ 2014-07-18 14:11 SunshineAtNoon 阅读(178) 评论(0) 推荐(0) 编辑
摘要: Given 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 rep... 阅读全文
posted @ 2014-07-18 14:00 SunshineAtNoon 阅读(221) 评论(0) 推荐(0) 编辑
摘要: Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.题解:参见http://www.cnblogs.com... 阅读全文
posted @ 2014-07-18 11:51 SunshineAtNoon 阅读(154) 评论(0) 推荐(0) 编辑
摘要: Then-queens puzzle is the problem of placingnqueens on ann×nchessboard such that no two queens attack each other.Given an integern, return all distinc... 阅读全文
posted @ 2014-07-18 11:41 SunshineAtNoon 阅读(237) 评论(0) 推荐(0) 编辑
摘要: Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo... 阅读全文
posted @ 2014-07-18 10:53 SunshineAtNoon 阅读(253) 评论(0) 推荐(0) 编辑