Java version Bisearch solution


  • 3
    Q
    //This is my Bisearch solution in java.
    
     public class Solution {
            public int findMin(int[] num) {
                int left = 0, right = num.length - 1;
                while(left < right){
                    int mid = (left + right) / 2;
                    if(num[left] > num[right]){
                        if(num[left] <= num[mid]){
                            left = mid + 1;
                        }else{
                            right = mid;
                        }
                    }else{
                        return num[left];
                    }
                }
                return num[left];
            }
        }

Log in to reply
 

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