摘要: Given an arraynums, write a function to move all0's to the end of it while maintaining the relative order of the non-zero elements.For example, givenn... 阅读全文
posted @ 2015-11-02 05:51 Sherry是小太阳 阅读(113) 评论(0) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2015-11-02 05:46 Sherry是小太阳 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Question:Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant di... 阅读全文
posted @ 2015-11-02 05:32 Sherry是小太阳 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Leetcode 78 SubsetGiven a set of distinct integers,S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The soluti... 阅读全文
posted @ 2015-03-17 10:41 Sherry是小太阳 阅读(313) 评论(0) 推荐(0) 编辑
摘要: Implementint sqrt(int x).Compute and return the square root ofx.求平方根, 用的是二分法. 从 0 - x, 使用二分的思想啊~为了防止overflow, 把low和up用long。然后return int类型就行了~据说还有一种牛顿迭... 阅读全文
posted @ 2015-02-25 07:43 Sherry是小太阳 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Rotate an array ofnelements to the right byksteps.For example, withn= 7 andk= 3, the array[1,2,3,4,5,6,7]is rotated to[5,6,7,1,2,3,4].Note:Try to come... 阅读全文
posted @ 2015-02-25 03:52 Sherry是小太阳 阅读(275) 评论(0) 推荐(0) 编辑
摘要: Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->... 阅读全文
posted @ 2015-02-17 00:23 Sherry是小太阳 阅读(146) 评论(0) 推荐(0) 编辑
摘要: A peak element is an element that is greater than its neighbors.Given an input array wherenum[i] ≠ num[i+1], find a peak element and return its index.... 阅读全文
posted @ 2015-02-16 22:20 Sherry是小太阳 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 思路就是砍一半, 适用于sorted array.时间复杂度O(lgn).每次都是取中间的跟target比较, 比target小的话目标值肯定在lower和mid之间, 比target大的话在mid和high之间~ 1 public int binarySearch(int num[], int t... 阅读全文
posted @ 2015-02-16 10:15 Sherry是小太阳 阅读(106) 评论(0) 推荐(0) 编辑
摘要: Given an array of sizen, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋times.You may assume that the arr... 阅读全文
posted @ 2015-02-16 09:49 Sherry是小太阳 阅读(113) 评论(0) 推荐(0) 编辑