Accepted C Solution with some explanation


  • 0
    R
    int findMin(int* nums, int numsSize) {
    	int p1=0;
    	int p2=numsSize-1;
    
    	while(p1<p2){
    		if(nums[p1]<nums[p2]){
    			return nums[p1];
    		}
    
    		int mid =(p1+p2)/2;
    		if(nums[mid] >= nums[p1]){
    			p1=mid+1;
    		} else {
    			p2=mid;
    		}
    	}
    
    	return nums[p1];
    }
    

    its a standard binary search.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.