当前位置: 首页 > news >正文

闯关leetcode——3285. Find Indices of Stable Mountains

大纲

  • 题目
    • 地址
    • 内容
  • 解题
    • 代码地址

题目

地址

https://leetcode.com/problems/find-indices-of-stable-mountains/description/

内容

There are n mountains in a row, and each mountain has a height. You are given an integer array height where height[i] represents the height of mountain i, and an integer threshold.

A mountain is called stable if the mountain just before it (if it exists) has a height strictly greater than threshold. Note that mountain 0 is not stable.

Return an array containing the indices of all stable mountains in any order.

Example 1:

Input: height = [1,2,3,4,5], threshold = 2
Output: [3,4]
Explanation:
Mountain 3 is stable because height[2] == 3 is greater than threshold == 2.
Mountain 4 is stable because height[3] == 4 is greater than threshold == 2.

Example 2:

Input: height = [10,1,10,1,10], threshold = 3
Output: [1,3]

Example 3:

Input: height = [10,1,10,1,10], threshold = 10
Output: []

Constraints:

  • 2 <= n == height.length <= 100
  • 1 <= height[i] <= 100
  • 1 <= threshold <= 100

解题

这题就是要记录一个数组中,比某个数大的下一个数的下标。这个问题有个边界,即只要遍历到最后一个元素的之前的元素即可。因为判断条件之和前一个元素有关系。

#include <vector>
using namespace std;class Solution {
public:vector<int> stableMountains(vector<int>& height, int threshold) {vector<int> result;for (int i = 0; i < height.size() - 1; i++) {if (height[i] > threshold) {result.push_back(i+1);}}return result;}
};

在这里插入图片描述

代码地址

https://github.com/f304646673/leetcode/tree/main/3285-Find-Indices-of-Stable-Mountains/cplusplus

http://www.lryc.cn/news/476790.html

相关文章:

  • 算法【Java】—— 动态规划之斐波那契数列模型
  • idea连接docker并构建镜像
  • 百度如何打造AI原生研发新范式?
  • RedisTemplate类中的常用方法粗解(简单明了,预计5分钟看完)
  • 鸿蒙ArkTS中的布局容器组件(Column、Row、Flex、 Stack、Grid)
  • 显存占用 显存测试
  • 快速入门CSS
  • AcWing 1073 树的中心 树形dp (详解)
  • modelscope下载Qwen2.5 72B 模型方法
  • 重学SpringBoot3-整合 Elasticsearch 8.x (二)使用Repository
  • 为什么说模拟电路的难点就在开通过程和关断过程?难在什么地方?
  • CubeIDE BUG-project‘hello‘has no explict encoding set hello
  • 在线PDF转图片网站
  • ps和top的区别
  • 自动驾驶上市潮中,会诞生下一个“英伟达”吗?
  • CSS 计数器:深入解析与高级应用
  • 【真题笔记】15年系统架构设计师要点总结
  • 斗破C++编程入门系列之三十九:多态性:纯虚函数和抽象类(四星斗师)
  • 目前美国的互联网环境
  • 从最小作用量原理推导牛顿三大定律
  • 【系统集成项目管理工程师教程】第4章 信息系统架构
  • docker下迁移elasticsearch的问题与解决方案
  • 占地1.1万平,2亿投资的智能仓储系统:高架库、AGV、码垛机器人……
  • 一个小程序如何对接多个收款账户?
  • L2G4000 InternVL 部署微调实践闯关任务
  • asynDriver-6-端口驱动
  • [免费]基于Python的Django+Vue3在线考试系统【论文+源码+SQL脚本】
  • Python使用爬虫
  • CommunityToolkit.Mvvm如何使用
  • Python小游戏20——超级玛丽