单调栈-Maximum Width Ramp
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的更多相关文章
- 【LeetCode】962. Maximum Width Ramp 解题报告(Python)
		
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址:https://leetco ...
 - [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 ...
 - 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 ...
 - 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 ...
 - 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 ...
 - 【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]. ...
 - 962. Maximum Width Ramp
		
本题题意: 在数组中,找到最大的j-i,使得i<j and A[i] <= A[j] 思路: 维持一个递减的栈,遇到比栈顶小的元素,进栈: 比大于等于栈顶的元素-> 找到栈中第一个小 ...
 - Codeforces 1107G Vasya and Maximum Profit 线段树最大子段和 + 单调栈
		
Codeforces 1107G 线段树最大子段和 + 单调栈 G. Vasya and Maximum Profit Description: Vasya got really tired of t ...
 - Maximum Xor Secondary CodeForces - 281D  (单调栈)
		
Bike loves looking for the second maximum element in the sequence. The second maximum element in the ...
 
随机推荐
- 1078 Hashing (25 分)
			
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive integ ...
 - 修改android项目sdk版本
			
1.右键单击项目--->properties---->Resource----->Android在Project Bulid Target对话框中选择你需要的Android版本.2. ...
 - python爬虫-scrapy日志
			
1.scrapy日志介绍 Scrapy的日志系统是实现了对python内置的日志的封装 scrapy也使用python日志级别分类 logging.CRITICAL logging.ERROE log ...
 - shell 之 case。。。esac多分支选择
			
case分支属于匹配执行的方式,它针对指定的变量预先设置一个可能的取值,判断该变量的实际取值是否与预设的某一个值相匹配,如果匹配上了,就执行相应的一组操作,如果没有任何值能够匹配,就执行预先设置的默认 ...
 - Pro SQL Server Internal (Dmitri Korotkev)电子书翻译P8-14(12w)
			
数据行与数据列 数据库的控件逻辑上分成8KB的页,这些页从0开始,连续排序,对特定的文件ID和页码有借鉴意义.页码编号一定是连续的,当SQL服务器中的数据库文件增加时,新的数据页从最高的页码开始编码. ...
 - 使用GitHub(二):配置并使用Git创建版本库
			
使用GitHub(二):配置并使用Git创建版本库 本文简单介绍使用GitHub对代码进行版本控制,包括添加SSHkey.配置Git.使用Git创建版本库并在GitHub上进行管理,主要目的是对学习内 ...
 - webpack从0到1超详细超基础学习教程
			
概念 自己是一个一听到webpack就头大,看着一堆不知道那是什么玩意的东西总觉得自己做好前端就行了,但是在使用vue-cli的时候总觉得要改其中的一些东西进行项目初始化的时候能够更好使用!所以想要根 ...
 - 把.net Core 项目迁移到VS2019 for MAC
			
VS2019 for MAC已经发布很长时间了,本以为项目移过去很麻烦,一直没有动作,最近呆家里快发霉了,决定研究研究,没想到一句代码都不需要动,直接完功,这下可以生产了.同学们可以放心整了. 本次平 ...
 - #AcWing系列课程Level-2笔记——5.高精度“+”算法
			
高精度"+"算法 编写高精度"+",记住下面的过程,代码也就游刃有余了! 1.首先我们要明白大整数是如何存储的? 2.其次存储完,如何运算? 高精度" ...
 - vue中的插槽(slot)
			
vue中的插槽,指的是子组件中提供给父组件使用的一个占位符,用<slot></slot>标签表示,父组件可以在这个占位符中填充任何模板代码,比如HTML.组件等,填充的内容会替 ...