Skip to content

Commit

Permalink
Time: 0 ms (100.00%), Space: 42.9 MB (84.20%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
tausiq2003 committed Aug 11, 2023
1 parent 823e918 commit 221cf3f
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Solution {
public int findMin(int[] nums) {
// 4 cases
// 1st: left of pivot
// 2nd: right of target
// 3rd: target
// 4th: pivot
int start = 0;
int end = nums.length-1;
// int tempstart = start;
// int tempend = end;
while(start < end){
int mid = start + (end - start) /2;
int b = mid-1;
int a = mid +1;
b = b < 0? mid:b;
a = a > nums.length-1? mid: a;


if (nums[a] < nums[mid]){
return nums[a];
}
else if(nums[b] > nums[mid]){
return nums[mid];
}
else if(nums[mid] == nums[start] && nums[mid] == nums[end]){
start++;
end--;

}
else if(nums[mid] >= nums[start] && !(nums[start] < nums[end])){
start = mid + 1;
}
else{
end = mid -1;
}
}
return nums[start];

}
}

0 comments on commit 221cf3f

Please sign in to comment.