Skip to main content

🟢 剑指 Offer II 069. 山峰数组的顶部

LeetCode 提示

题目难度 简单

原题链接 🔗 leetcode

题解 1.py#

class Solution:    def peakIndexInMountainArray(self, arr: List[int]) -> int:        left, right = 0, len(arr)-1        while left < right:            mid = (left + right) // 2            if arr[mid-1] < arr[mid] and arr[mid] > arr[mid+1]:                return mid            if arr[mid-1] > arr[mid]:                right = mid-1            else:                left = mid+1                return left