Accepted 6 lines of Java code


  • 0
    I
    public int findPeakElement(int [] num) {
       int length = num.length, left = 0, right = length - 1;
       while(true){    
          if(left==right) return left;
          int mid = (left+right)/2;
          if(num[mid] < num[mid+1]) left = mid+1;
          else right = mid;
       }
    }

Log in to reply
 

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