2016年6月29日星期三

[LeetCode] #81 Search in Rotated Sorted Array II

Do not try to use binary search!!!!! worst case time complexity: O(n)

binarySearch(start, end) {
    if (nums[start] == nums[mid] == nums[end]) { // if always hit this case until the last 1 elem, O(n)
        binarySearch(start, mid);
        binarySearch(mid + 1, end);
    }
}

没有评论:

发表评论