leetcode---search-in-rotated-sorted-array-ii---查找
2018-03-03 16:27
363 查看
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 array.
参考
http://blog.csdn.net/linhuanmars/article/details/20588511
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 array.
class Solution { public: bool search(int A[], int n, int target) { int l = 0; int r = n-1; while(l <= r) { int m = (l + r) / 2; if(A[m] == target) return true; if(A[l] < A[m]) { if(A[m] > target && A[l] <= target) r = m-1; else l = m+1; } else if(A[m] < A[l]) { if(A[m] < target && A[r] >= target) l = m+1; else r = m-1; } else ++l; } return false; } };
参考
http://blog.csdn.net/linhuanmars/article/details/20588511
相关文章推荐
- LeetCode-Search in Rotated Sorted Array II-在旋转数组中搜索-二分查找
- leetcode 题解:Search in Rotated Sorted Array II (旋转已排序数组查找2)
- LeetCode 81 Search in Rotated Sorted Array II(循环有序数组中的查找问题)
- leetcode_81——Search in Rotated Sorted Array II(二分查找)
- 解题报告:LeetCode Search in Rotated Sorted Array II(循环数字查找)
- leetcode 刷题之路 35 Search in Rotated Sorted Array II (旋转排序数组查找终极版)
- leetcode 81. Search in Rotated Sorted Array II-旋转数组|二分查找
- leetcode-81-Search in Rotated Sorted Array II 查找
- Leetcode刷题记—— 81. Search in Rotated Sorted Array II(在翻转数组中查找2)
- LeetCode @ Search in Rotated Sorted ArrayII 旋转数组查找II
- leetcode 81. Search in Rotated Sorted Array II 旋转数组查找+二分查找
- Search in Rotated Sorted Array II [LeetCode]
- [LeetCode]81 Search in Rotated Sorted Array II
- Leetcode 81. Search in Rotated Sorted Array II (Medium) (java)
- [LeetCode]Search in Rotated Sorted Array I&II
- LeetCode: 81. Search in Rotated Sorted Array II
- LeetCode | Search in Rotated Sorted Array(在旋转数组中查找)
- LeetCode(33)(81) Search in Rotated Sorted Array I II
- Search in Rotated Sorted Array II-LeetCode
- Leetcode 81. Search in Rotated Sorted Array II