leetcode 456. 132 模式(单调栈)

给你一个整数数组 nums ,数组中共有 n 个整数。132 模式的子序列 由三个整数 nums[i]、nums[j] 和 nums[k] 组成,并同时满足:i < j < k 和 nums[i] < nums[k] < nums[j] 。

如果 nums 中存在 132 模式的子序列 ,返回 true ;否则,返回 false 。

进阶:很容易想到时间复杂度为 O(n^2) 的解决方案,你可以设计一个时间复杂度为 O(n logn) 或 O(n) 的解决方案吗?

示例 1:

输入:nums = [1,2,3,4]
输出:false
解释:序列中不存在 132 模式的子序列。

代码

class Solution {public boolean find132pattern(int[] nums) {Stack<Integer> stack = new Stack<>();int sec=Integer.MIN_VALUE;for(int i=nums.length-1;i>=0;i--){if(nums[i]<sec)return true;while (!stack.isEmpty()&&nums[i]>stack.peek()){sec=stack.pop();}stack.push(nums[i]);}return false;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391559.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

seaborn分类数据可视:散点图|箱型图|小提琴图|lv图|柱状图|折线图

一、散点图stripplot( ) 与swarmplot&#xff08;&#xff09; 1.分类散点图stripplot( ) 用法stripplot(xNone, yNone, hueNone, dataNone, orderNone, hue_orderNone,jitterTrue, dodgeFalse, orientNone, colorNone, paletteNone,size5, edgecolor"gray", linewi…

数据图表可视化_数据可视化十大最有用的图表

数据图表可视化分析师每天使用的最佳数据可视化图表列表。 (List of best data visualization charts that Analysts use on a daily basis.) Presenting information or data in a visual format is one of the most effective ways. Researchers have proved that the human …

javascript实现自动添加文本框功能

转自&#xff1a;http://www.cnblogs.com/damonlan/archive/2011/08/03/2126046.html 昨天&#xff0c;我们公司的网络小组决定为公司做一个内部的网站&#xff0c;主要是为员工比如发布公告啊、填写相应信息、投诉、问题等等需求。我那同事给了我以下需求&#xff1a; 1.点击一…

从Mysql slave system lock延迟说开去

本文主要分析 sql thread中system lock出现的原因&#xff0c;但是笔者并明没有系统的学习过master-slave的代码&#xff0c;这也是2018年的一个目标&#xff0c;2018年我都排满了&#xff0c;悲剧。所以如果有错误请指出&#xff0c;也作为一个笔记用于后期学习。同时也给出笔…

传智播客全栈_播客:从家庭学生到自学成才的全栈开发人员

传智播客全栈In this weeks episode of the freeCodeCamp podcast, Abbey chats with Madison Kanna, a full-stack developer who works remotely for Mediavine. Madison describes how homeschooling affected her future learning style, how she tackles imposter syndrom…

leetcode 82. 删除排序链表中的重复元素 II(map)

解题思路 map记录数字出现的次数&#xff0c;出现次数大于1的数字从链表中移除 代码 /*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode() {}* ListNode(int val) { this.val val; }* ListNode(…

python 列表、字典多排序问题

版权声明&#xff1a;本文为博主原创文章&#xff0c;遵循 CC 4.0 by-sa 版权协议&#xff0c;转载请附上原文出处链接和本声明。本文链接&#xff1a;https://blog.csdn.net/justin051/article/details/84289189Python使用sorted函数来排序&#xff1a; l [2,1,3,5,7,3]print…

接facebook广告_Facebook广告分析

接facebook广告Is our company’s Facebook advertising even worth the effort?我们公司的Facebook广告是否值得努力&#xff1f; 题&#xff1a; (QUESTION:) A company would like to know if their advertising is effective. Before you start, yes…. Facebook does ha…

如何创建自定义进度栏

Originally published on www.florin-pop.com最初发布在www.florin-pop.com The theme for week #14 of the Weekly Coding Challenge is: 每周编码挑战第14周的主题是&#xff1a; 进度条 (Progress Bar) A progress bar is used to show how far a user action is still in…

基于SpringBoot的CodeGenerator

title: 基于SpringBoot的CodeGenerator tags: SpringBootMybatis生成器PageHelper categories: springboot date: 2017-11-21 15:13:33背景 目前组织上对于一个基础的crud的框架需求较多 因此选择了SpringBoot作为基础选型。 Spring Boot是由Pivotal团队提供的全新框架&#xf…

seaborn线性关系数据可视化:时间线图|热图|结构化图表可视化

一、线性关系数据可视化lmplot( ) 表示对所统计的数据做散点图&#xff0c;并拟合一个一元线性回归关系。 lmplot(x, y, data, hueNone, colNone, rowNone, paletteNone,col_wrapNone, height5, aspect1,markers"o", sharexTrue,shareyTrue, hue_orderNone, col_orde…

hdu 1257

http://acm.hdu.edu.cn/showproblem.php?pid1257 题意&#xff1a;有个拦截系统&#xff0c;这个系统在最开始可以拦截任意高度的导弹&#xff0c;但是之后只能拦截不超过这个导弹高度的导弹&#xff0c;现在有N个导弹需要拦截&#xff0c;问你最少需要多少个拦截系统 思路&am…

eda可视化_5用于探索性数据分析(EDA)的高级可视化

eda可视化Early morning, a lady comes to meet Sherlock Holmes and Watson. Even before the lady opens her mouth and starts telling the reason for her visit, Sherlock can tell a lot about a person by his sheer power of observation and deduction. Similarly, we…

我的AWS开发人员考试未通过。 现在怎么办?

I have just taken the AWS Certified Developer - Associate Exam on July 1st of 2019. The result? I failed.我刚刚在2019年7月1日参加了AWS认证开发人员-联考。结果如何&#xff1f; 我失败了。 The AWS Certified Developer - Associate (DVA-C01) has a scaled score …

关系数据可视化gephi

表示对象之间的关系&#xff0c;可通过gephi软件实现&#xff0c;软件下载官方地址https://gephi.org/users/download/ 如何来表示两个对象之间的关系&#xff1f; 把对象变成点&#xff0c;点的大小、颜色可以是它的两个参数&#xff0c;两个点之间的关系可以用连线表示。连线…

Hyperledger Fabric 1.0 从零开始(十二)——fabric-sdk-java应用

Hyperledger Fabric 1.0 从零开始&#xff08;十&#xff09;——智能合约&#xff08;参阅&#xff1a;Hyperledger Fabric Chaincode for Operators——实操智能合约&#xff09; Hyperledger Fabric 1.0 从零开始&#xff08;十一&#xff09;——CouchDB&#xff08;参阅&a…

css跑道_如何不超出跑道:计划种子的简单方法

css跑道There’s lots of startup advice floating around. I’m going to give you a very practical one that’s often missed — how to plan your early growth. The seed round is usually devoted to finding your product-market fit, meaning you start with no or li…

将json 填入表格_如何将Google表格用作JSON端点

将json 填入表格UPDATE: 5/13/2020 - New Share Dialog Box steps available below.更新&#xff1a;5/13/2020-下面提供了 新共享对话框步骤。 Thanks Erica H!谢谢埃里卡H&#xff01; Are you building a prototype dynamic web application and need to collaborate with …

leetcode 173. 二叉搜索树迭代器

实现一个二叉搜索树迭代器类BSTIterator &#xff0c;表示一个按中序遍历二叉搜索树&#xff08;BST&#xff09;的迭代器&#xff1a; BSTIterator(TreeNode root) 初始化 BSTIterator 类的一个对象。BST 的根节点 root 会作为构造函数的一部分给出。指针应初始化为一个不存在…

jyputer notebook 、jypyter、IPython basics

1 、修改jupyter默认工作目录&#xff1a;打开cmd&#xff0c;在命令行下指定想要进的工作目录&#xff0c;即键入“cd d/ G:\0工作面试\学习记录”标红部分是想要进入的工作目录。 2、Tab补全 a、在命令行输入表达式时&#xff0c;按下Tab键即可为任意变量&#xff08;对象、…