diff --git a/Sample b/Sample index ceae9f98..8c46e98d 100644 --- a/Sample +++ b/Sample @@ -1,7 +1,50 @@ -// Time Complexity : +// Time Complexity : log(n) // Space Complexity : // Did this code successfully run on Leetcode : // Any problem you faced while coding this : +class Solution { + public int search(int[] nums, int target) { + int left=-10000; //max=-10000 because max can not be less than -10,000 + int idxleft=-1; //finding the idx where the max value is at + int right=10000; // min=10,000 because there can;t be min greater than 10,000 + int idxright=-1; //finding the idx where the min value is at. + for(int i=0; ileft){ // finding if the current value is > max + left=nums[i]; + idxleft=i; + } + if(nums[i]nums[idxright] && idxright != nums.length-1){ + return findidx(nums,idxleft,idxright+1,target); + }else if(target>nums[idxright] && idxright==nums.length-1 || target