Simple iterative solution in Java


  • 0
    H
    public class Solution {
        public int findMin(int[] nums) {
            int lo = 0, hi = nums.length-1, mid;
            
            while(lo < hi){
                mid = (lo + hi)/2;
                
                if(nums[mid] > nums[hi]){
                    lo = mid + 1;
                }else{
                    hi = mid;
                }
            }
            
            return nums[lo];
        }    
    }

Log in to reply
 

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