Ryan’s leetcode Blog
显示标签为“
binary search
”的博文。
显示所有博文
显示标签为“
binary search
”的博文。
显示所有博文
2015年7月23日星期四
binary search 总结
›
二分法比较简单, 时间复杂度为O(log n) mid = right + (left - right) / 2 防止left right 都大时候溢出 两种二分法 1. start <= end 每次start = mid + 1 或者 end = mid - 1 ...
2015年6月25日星期四
Sqrt(x) leetcode
›
Implement int sqrt(int x) . 注意这道题是返回int 的平方根 所以: sqrt(3) = 1 sqrt(4) = 2 sqrt(5) = 2 sqrt(10) = 3 用二分法来判定 逐步找到平方根, 但是要注意的是只要符合 m...
2015年6月8日星期一
Find Minimum in Rotated Sorted Array II leetcode
›
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 t...
Find Minimum in Rotated Sorted Array leetcode
›
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 t...
2015年4月29日星期三
Convert Sorted Array to Binary Search Tree leetcode
›
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 选择中点构造根节点然后递归构造左子树和右子树 因为递归时候要记录一个起始位置一个...
2015年4月14日星期二
Search a 2D Matrix II
›
Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it. This matrix has the following pro...
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 ...
First Bad Version
›
The code base version is an integer and start from 1 to n. One day, someone commit a bad version in the code case, so it caused itself and ...
2 条评论:
2015年4月13日星期一
Search a 2D Matrix leetcode
›
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in ea...
2015年4月12日星期日
Search in Rotated Sorted Array II leetcode
›
Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? H...
Search in Rotated Sorted Array leetcode
›
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 ar...
Search Insert Position leetcode
›
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were ins...
Search for a Range leetcode
›
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity ...
Binary Search
›
For a given sorted array (ascending order) and a target number, find the first index of this number in O(log n) time complexity. If the t...
›
主页
查看网络版本