Last active
August 9, 2020 06:26
-
-
Save oyekanmiayo/99034999aca067c156efe419bb54c1ac to your computer and use it in GitHub Desktop.
Solution to " Find Minimum in Rotated Sorted Array II" on Leetcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
// Final solution | |
public int findMin(int[] nums) { | |
int start = 0; | |
int end = nums.length - 1; | |
while(start < end){ | |
int mid = start + (end - start) / 2; | |
if(nums[mid] < nums[end]){ | |
end = mid; | |
} else if (nums[mid] > nums[end]){ | |
start = mid + 1; | |
} else { | |
end--; | |
} | |
} | |
return nums[end]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The worst case is O(N), where all the elements are duplicates. Amortized is O(logn).