您的位置:首页 > 其它

Binary153FindMinimumInRotatedSortedArray

2016-12-31 06:07 155 查看

Method 1

O(n) method. Skip here.

Method 2

O(logn) method. Use binary search.

Failed Case {4,5,6,1,2,3} for bugtest method

Conditions are right, but didn’t think if should be
start = mid + 1;
or
start = mid
. 我们需要保证目标值时刻在start和end范围内, 因此要考虑如果用mid+1会不会破坏这个原则.

后来想了一个新方法, mid只用来移动start和end, 用start和end来做所有判断. 类似的方法有很多

https://discuss.leetcode.com/topic/73025/9-lines-java-binary-search

BinarySearch的精髓只是运用二分法, 至于conditions和moving rule都是灵活的!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: