
Binary Search
文章平均质量分 66
豆腐脑是咸的
这个作者很懒,什么都没留下…
展开
-
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. You may assume no duplicate exists in原创 2015-01-06 19:39:52 · 298 阅读 · 0 评论 -
Find Minimum in Rotated Sorted Array II (Java)
Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose a sorted array is rotated at some pivot unk原创 2015-01-24 10:48:31 · 330 阅读 · 0 评论 -
Search for a Range (Java)
Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the target is not found原创 2015-01-05 21:42:41 · 517 阅读 · 0 评论 -
Find Peak Element (Java)
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 index. The array may contain multiple peaks, i原创 2015-01-05 21:42:19 · 399 阅读 · 0 评论 -
Search a 2D Matrix (Java)
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each原创 2015-01-05 17:10:10 · 279 阅读 · 0 评论 -
Sqrt(x) (Java)
Implement int sqrt(int x). Compute and return the square root of x. 用二分法来查找,x的根肯定是大于0小于x的,mid作为x的根,用mid * mid与x比大小,然后接着查找,如果有则返回,不能开尽的用较小的整数代替(根向下取整)。 Source public class Solution { pu原创 2015-01-05 16:16:02 · 470 阅读 · 0 评论 -
Pow(x, n) (Java)
Implement pow(x, n). 注意n为负数的情况 Source public class Solution { public double pow(double x, int n) { if(n == 0) return 1; if(n < 0){ n = -n; x = 1 / x;原创 2015-01-05 19:40:28 · 371 阅读 · 0 评论 -
Search Insert Position (Java)
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 inserted in order. You may assume no duplicates in the array.原创 2015-01-05 16:34:30 · 354 阅读 · 0 评论 -
Search in Rotated Sorted Array (Java)
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 value to search. If found in the array retur原创 2015-01-23 11:35:45 · 337 阅读 · 0 评论 -
Search in Rotated Sorted Array II
Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Write a function to determine if a given target is in the原创 2015-01-23 18:08:01 · 294 阅读 · 0 评论 -
Divide Two Integers (Java)
Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 这道题题意是算余数不能用乘、除和取模运算。 循环减会超时。 可以采用位运算,下次写注意下。 这道题主要在对于边界的处理上,-2147483648,原创 2015-01-22 10:44:04 · 409 阅读 · 0 评论 -
Median of Two Sorted Arrays (Java)
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 参考:http://blog.youkuaiyun.com/yutianzui原创 2015-02-12 15:31:42 · 424 阅读 · 0 评论