g2901_3000.s2951_find_the_peaks.Solution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
The newest version!
package g2901_3000.s2951_find_the_peaks;
// #Easy #Array #Enumeration #2024_01_15_Time_1_ms_(100.00%)_Space_43.8_MB_(79.61%)
import java.util.ArrayList;
import java.util.List;
public class Solution {
public List findPeaks(int[] mountain) {
List list = new ArrayList<>();
for (int i = 1; i < mountain.length - 1; i++) {
if ((mountain[i - 1] < mountain[i]) && (mountain[i] > mountain[i + 1])) {
list.add(i);
}
}
return list;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy