Why while(low < high)?not while(low <= high)?Thank you


  • -1
    W

    public class Solution {
    public int findMin(int[] nums) {
    int low = 0;
    int high = nums.length-1;

    //Why while(low < high)?not while(low <= high)?Thank you
    while(low < high){
    int middle = (low+high)/2;
    if(nums[middle] > nums[high]){
    low = middle+1;
    }else{
    high = middle;
    }
    }
    return nums[low];

    }
    

    }


Log in to reply
 

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