find_peak_element

  • 2022-12-14
  • 浏览 (524)

find_peak_element.py 源码

from typing import List


# 寻找峰值

class Solution:

    # 暴力法,线性查找
    def findPeakElement_1(self, nums: List[int]) -> int:
        for i in range(1, len(nums) - 1):
            if nums[i - 1] < nums[i] > nums[i + 1]:
                return i
        return 0

你可能感兴趣的文章

first_last_sort_array

perfect_square

search_rotated_sorted_array

0  赞