python-algorithm
leetcode 2951. Find the Peaks
무적김두칠
2023. 12. 27. 22:01
https://leetcode.com/problems/find-the-peaks/description/
Find the Peaks - LeetCode
Can you solve this real interview question? Find the Peaks - You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array. Return an array that consists of indices of peaks in the given array in any order. Notes: * A p
leetcode.com
1 2 3 4 5 6 7 8 9 | class Solution: def findPeaks(self, mountain: List[int]) -> List[int]: answer = [] for i in range(1, len(mountain) - 1): if mountain[i-1]< mountain[i] and mountain[i] > mountain[i+1]: answer.append(i) return answer | cs |
반응형