3285. 找到稳定山的下标
有 n
座山排成一列,每座山都有一个高度。给你一个整数数组 height
,其中 height[i]
表示第 i
座山的高度,再给你一个整数 threshold
。
对于下标不为 0
的一座山,如果它左侧相邻的山的高度 严格大于 threshold
,那么我们称它是 稳定 的。我们定义下标为 0
的山 不是 稳定的。
请你返回一个数组,包含所有 稳定 山的下标,你可以以 任意 顺序返回下标数组。
示例 1:
输入:height = [1,2,3,4,5], threshold = 2
输出:[3,4]
解释:
height[2] == 3
大于 threshold == 2
。height[3] == 4
大于 threshold == 2
.示例 2:
输入:height = [10,1,10,1,10], threshold = 3
输出:[1,3]
示例 3:
输入:height = [10,1,10,1,10], threshold = 10
输出:[]
提示:
2 <= n == height.length <= 100
1 <= height[i] <= 100
1 <= threshold <= 100
相似题目
原站题解
rust 解法, 执行用时: 0 ms, 内存消耗: 2.2 MB, 提交时间: 2024-12-19 07:50:50
impl Solution {pub fn stable_mountains(height: Vec<i32>, threshold: i32) -> Vec<i32> {let mut result = Vec::new();for i in 1..height.len() {if height[i - 1] > threshold {result.push(i as i32);}}result}}
javascript 解法, 执行用时: 1 ms, 内存消耗: 52 MB, 提交时间: 2024-12-19 07:50:32
/*** @param {number[]} height* @param {number} threshold* @return {number[]}*/var stableMountains = function(height, threshold) {const result = [];for (let i = 1; i < height.length; i++) {if (height[i - 1] > threshold) {result.push(i);}}return result;};
cpp 解法, 执行用时: 1 ms, 内存消耗: 27.6 MB, 提交时间: 2024-12-19 07:50:19
class Solution {public:vector<int> stableMountains(vector<int>& height, int threshold) {vector<int> result;for (int i = 1; i < height.size(); i++) {if (height[i - 1] > threshold) {result.push_back(i);}}return result;}};
java 解法, 执行用时: 1 ms, 内存消耗: 43.8 MB, 提交时间: 2024-12-19 07:50:05
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;}}
golang 解法, 执行用时: 5 ms, 内存消耗: 2.9 MB, 提交时间: 2024-09-18 16:56:11
func stableMountains(height []int, threshold int) []int {var ans []intn := len(height)for i := 1; i < n; i++ {if height[i-1] > threshold {ans = append(ans, i)}}return ans}
python3 解法, 执行用时: 52 ms, 内存消耗: 16.5 MB, 提交时间: 2024-09-18 16:53:13
class Solution:def stableMountains(self, height: List[int], threshold: int) -> List[int]:return [i for i, h in enumerate(height[:-1], 1) if h > threshold]
python3 解法, 执行用时: 51 ms, 内存消耗: 16.4 MB, 提交时间: 2024-09-18 09:55:06
class Solution:def stableMountains(self, height: List[int], threshold: int) -> List[int]:ans = []for i in range(1, len(height)):if height[i-1] > threshold:ans.append(i)return ans