查找算法


class Solution {
    func minArray(_ numbers: [Int]) -> Int {
      var left = 0
      var right = numbers.count - 1
    
      while left < right {
      
        let mid = (left + right) / 2
      
        if numbers[mid] < numbers[right] {
          right = mid
        } else if numbers[mid] > numbers[right] {
          left = mid + 1
        } else {
          right -= 1
        }
      }
      return numbers[left]
    }
}



Loading Disqus comments...
Table of Contents