2016年5月15日

Find Minimum in Rotated Sorted Array

摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. 阅读全文

posted @ 2016-05-15 23:08 Sheryl Wang 阅读(112) 评论(0) 推荐(0) 编辑

Search in Rotated Sorted Array

摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target va 阅读全文

posted @ 2016-05-15 23:07 Sheryl Wang 阅读(115) 评论(0) 推荐(0) 编辑

Binary Search 二分查找总结

摘要: Binary Search基本的复杂度为O(logn)。如果提示需要对O(n)的算法进行优化,非常可能就是二分,另外二分一般出现在排序数组或者变形后的排序数组(rotated array)当中。二分主要有两种,binary search on index(index上的二分)和binary sear 阅读全文

posted @ 2016-05-15 23:06 Sheryl Wang 阅读(286) 评论(0) 推荐(0) 编辑

Find Peak Element

摘要: A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ num[i+1], find a peak element and return its inde 阅读全文

posted @ 2016-05-15 23:01 Sheryl Wang 阅读(189) 评论(0) 推荐(0) 编辑

Wood Cut

摘要: http://www.lintcode.com/zh-cn/problem/wood-cut/ 有一些原木,现在想把这些木头切割成一些长度相同的小段木头,需要得到的小段的数目至少为 k。当然,我们希望得到的小段越长越好,你需要计算能够得到的小段木头的最大长度。 注意事项 木头长度的单位是厘米。原木的 阅读全文

posted @ 2016-05-15 22:38 Sheryl Wang 阅读(393) 评论(0) 推荐(0) 编辑

Sqrt(x)

摘要: Implement int sqrt(int x). Compute and return the square root of x. 求一个数的开方,binary search on result 二分结果的典型。 对于0和1直接返回1。后面的left = 1 ,right 为 x/2。代码如下: 阅读全文

posted @ 2016-05-15 22:08 Sheryl Wang 阅读(172) 评论(0) 推荐(0) 编辑

Lowest Common Ancestor of a Binary Tree

摘要: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文

posted @ 2016-05-15 17:05 Sheryl Wang 阅读(194) 评论(0) 推荐(0) 编辑

导航