2020-01-23 19:39:26

问题描述:

问题求解:

    public int maxWidthRamp(int[] A) {
Stack<Integer> stack = new Stack<>();
int res = 0;
int n = A.length;
for (int i = 0; i < n; i++) {
if (stack.isEmpty() || A[stack.peek()] > A[i]) {
stack.add(i);
}
}
for (int i = n - 1; i > res; i--) {
while (!stack.isEmpty() && A[stack.peek()] <= A[i]) {
res = Math.max(res, i - stack.pop());
}
}
return res;
}

  

单调栈-Maximum Width Ramp的更多相关文章

  1. 【LeetCode】962. Maximum Width Ramp 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址:https://leetco ...

  2. [Swift]LeetCode962. 最大宽度坡 | Maximum Width Ramp

    Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The ...

  3. Maximum Width Ramp LT962

    Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The ...

  4. 116th LeetCode Weekly Contest Maximum Width Ramp

    Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The ...

  5. LC 962. Maximum Width Ramp

    Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j].  The ...

  6. 【leetcode】962. Maximum Width Ramp

    题目如下: Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. ...

  7. 962. Maximum Width Ramp

    本题题意: 在数组中,找到最大的j-i,使得i<j and A[i] <= A[j] 思路: 维持一个递减的栈,遇到比栈顶小的元素,进栈: 比大于等于栈顶的元素-> 找到栈中第一个小 ...

  8. Codeforces 1107G Vasya and Maximum Profit 线段树最大子段和 + 单调栈

    Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of t ...

  9. Maximum Xor Secondary CodeForces - 281D (单调栈)

    Bike loves looking for the second maximum element in the sequence. The second maximum element in the ...

随机推荐

  1. 内核融合:GPU深度学习的“加速神器”

    ​编者按:在深度学习"红透"半边天的同时,当前很多深度学习框架却面临着共同的性能问题:被频繁调用的代数运算符严重影响模型的执行效率. 本文中,微软亚洲研究院研究员薛继龙将为大家介绍 ...

  2. hexo文章编写部分语法总结以及hexo使用

    一.hexo的使用 1.1 新建一篇文章 1 $ hexo new [layout] <title> 1.2. 生成静态文件 1 $ hexo generate 可简写为 1 $ hexo ...

  3. Nginx_安装

    1. 安装步骤 上传nginx上传nginx安装包到linux 安装gcc 1 yum -y install gcc-c++ gcc 查看是否安装gcc: 1 gcc -v 安装依赖库 1 yum - ...

  4. nginx图片过滤处理模块http_image_filter_module安装配置

    http_image_filter_module是nginx提供的集成图片处理模块,支持nginx-0.7.54以后的版本,在网站访问量不是很高磁盘有限不想生成多余的图片文件的前提下可,就可以用它实时 ...

  5. IdentityServer4.FreeSql 持久化实现

    前言 故事是这样开始的: 然后突然又来了句... 扪心自问自从不知道怎么当了 FreeSql 开发群 () 的管理以来, 几乎没有给 FreeSql 做过什么贡献...惭愧惭愧. 借此机会, 似乎可以 ...

  6. MYSQL对数据库和表的基本操作

    CREATE DATABASE testdb CHARSET=UTF8 创建一个数据库 名字叫做testdb USE testdb; 选择数据库 CREATE TABLE testTable1( ) ...

  7. 07.深入浅出 Spring Boot - 数据访问之Mybatis(附代码下载)

    MyBatis 在Spring Boot应用非常广,非常强大的一个半自动的ORM框架. 代码下载:https://github.com/Jackson0714/study-spring-boot.gi ...

  8. Web最佳实践阅读总结(2)

    代码符合标准 标准的页面会保证正确的渲染 页面容易被搜索引擎搜索,提高搜索排名(SEO) 提高网站的易用性 网页更好维护和扩展(Validator,HTML Validator 属于Firefox插件 ...

  9. 微信小程序实战(一)之仿美丽说

    被美丽说少女粉吸引,就想着自己也写一个来练练手,正好最近在学习微信小程序.接下来让我们分享一下我的学习历程吧! 选题 其实纠结了好久该仿什么,看到别人都写的差不多了,自己却还没有动手,很着急,那两天一 ...

  10. vue自定义指令要点

    vue自定义指令的基础使用这里就不阐述,看官网文档:https://cn.vuejs.org/v2/guide/custom-directive.html 本文用一个实例描述自定义指令的要点,自定义一 ...