记录
2025.4.16
题目:
思路:
遍历。
解题步骤:
从下标为 1 的元素开始遍历,如果前一个下标的元素严格大于 threshold,则将这一个元素的下标加入结果数组中。遍历完成后,返回结果数组。
代码:
class Solution {
public List<Integer> stableMountains(int[] height, int threshold) {
List<Integer> result = new ArrayList<>();
for (int i = 1; i < height.length; i++) {
if (height[i - 1] > threshold) {
result.add(i);
}
}
return result;
}
}
复杂度:
O(N)
O(N)