2951. Find the Peaks Easy
1/**
2 * [2951] Find the Peaks
3 *
4 * You are given a 0-indexed array mountain. Your task is to find all the peaks in the mountain array.
5 * Return an array that consists of indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --> of peaks in the given array in any order.
6 * Notes:
7 *
8 * A peak is defined as an element that is strictly greater than its neighboring elements.
9 * The first and last elements of the array are not a peak.
10 *
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: mountain = [2,4,4]
15 * Output: []
16 * Explanation: mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.
17 * mountain[1] also can not be a peak because it is not strictly greater than mountain[2].
18 * So the answer is [].
19 *
20 * <strong class="example">Example 2:
21 *
22 * Input: mountain = [1,4,3,8,5]
23 * Output: [1,3]
24 * Explanation: mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.
25 * mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].
26 * But mountain [1] and mountain[3] are strictly greater than their neighboring elements.
27 * So the answer is [1,3].
28 *
29 *
30 * Constraints:
31 *
32 * 3 <= mountain.length <= 100
33 * 1 <= mountain[i] <= 100
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/find-the-peaks/
39// discuss: https://leetcode.com/problems/find-the-peaks/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn find_peaks(mountain: Vec<i32>) -> Vec<i32> {
45 vec![]
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2951() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.