ZhengXingchi / ZhengXingchi.github.io

Apache License 2.0
0 stars 0 forks source link

剑指offer(6)旋转数组中的最小数字 #33

Open ZhengXingchi opened 4 years ago

ZhengXingchi commented 4 years ago

二分查找

   function minNumberInRotateArray2(rotateArray) {
      let left = 0,
        right = rotateArray.length - 1;
      while (right - left > 1) {
        let mid = left + (right - left >> 1);//注意 位运算的优先级低于加减乘除
        if (rotateArray[mid] > rotateArray[right]) {
          left = mid;
        } else {
          right = mid;
        }
      }
      return Math.min(rotateArray[left], rotateArray[right]);
    }