Leetcode 946. Validate Stack Sequences 验证栈序列
946. Validate Stack Sequences
题目描述
Given two sequences pushed and popped with distinct values, return true if and only if this could have been the result of a sequence of push and pop operations on an initially empty stack.
示例
示例1
Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
Output: true
Explanation: We might do the following sequence:
push(1), push(2), push(3), push(4), pop() -> 4,
push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1
示例2
Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
Output: false
Explanation: 1 cannot be popped before 2.
解答
这道题很简单,把pushed数组里面的每个数字入栈,然后当push的值和popped里面的第一个未处理的值相等的时候,就进入循环,将popped数组里面的值从栈中移除。
最后判断popped数组里面的值是否处理完。
1 |
class {
|
Leetcode 946. Validate Stack Sequences 验证栈序列的更多相关文章
- 946. Validate Stack Sequences验证栈序列
网址:https://leetcode.com/problems/validate-stack-sequences/ 参考:https://leetcode.com/problems/validate ...
- Leetcode946. Validate Stack Sequences验证栈序列
给定 pushed 和 popped 两个序列,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 true:否则,返回 false . 示例 1: 输入:pus ...
- 第31题:LeetCode946. Validate Stack Sequences验证栈的序列
题目 给定 pushed 和 popped 两个序列,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 true:否则,返回 false . 示例 1: 输入: ...
- (栈)leetcode 946. Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could ha ...
- 946. Validate Stack Sequences
946. Validate Stack Sequences class Solution { public: bool validateStackSequences(vector<int> ...
- 【LeetCode】946. Validate Stack Sequences 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 模拟过程 日期 题目地址:https://leetc ...
- 【leetcode】946. Validate Stack Sequences
题目如下: Given two sequences pushed and popped with distinct values, return true if and only if this co ...
- LeetCode 946. 验证栈序列(Validate Stack Sequences) 26
946. 验证栈序列 946. Validate Stack Sequences 题目描述 Given two sequences pushed and popped with distinct va ...
- 112th LeetCode Weekly Contest Validate Stack Sequences
Given two sequences pushed and popped with distinct values, return true if and only if this could ha ...
随机推荐
- ZJNU 1125 - A == B ?——中级
处理后再判断即可,处理过程注意考虑全面. /* Written By. StelaYuri */ #include<iostream> #include<string> usi ...
- Linux-进程状态和system函数
1.进程的5种状态 (1).就绪态. 这个进程当前所有运行条件就绪,只要得到CPU时间就能直接运行. (2).运行态 就绪态时得到了CPU就进入运行态开始运行. (3).僵尸态 进程已经结束但是父进程 ...
- 初次运行Git前的配置
初次运行Git前的配置 一.初次运行 Git 前的配置 一般在新的系统上,我们都需要先配置下自己的 Git 工作环境.配置工作只需一次,以后升级时还会沿用现在的配置.当然,如果需要,你随时可以用相同的 ...
- Windows、Linux(Ubuntu)修改 pip 镜像源
一.Windows 修改 pip 镜像源 1.win + R 打开运行,输入 %APPDATA% 2.按下回车,打开文件夹. 3.在该文件夹下,新建文件夹,命名 pip. 4.进入 pip 文件夹, ...
- drf中的jwt使用与手动签发token、校验用户
jwt认证 1)session存储token,需要数据库参与,耗服务器资源.低效2)缓存存token,需要缓存参与,高效,不易集群3)客户端存token,服务器存签发与交易token的算法,高效,易集 ...
- Proe5.0导出PDF至配置文件的相关方法,VC++
定义文件bcsMessage.txt PLM PLM PLM # login login 测试 # Active messagebox menu Active messagebox menu 激活菜单 ...
- 吴裕雄--天生自然 PYTHON3开发学习:日期和时间
import time; # 引入time模块 ticks = time.time() print ("当前时间戳为:", ticks) import time localtime ...
- C# 使用 HttpPost 请求调用 WebService (转)
转自 https://www.cnblogs.com/Brambling/p/7266482.html 之前调用 WebService 都是直接添加服务引用,然后调用 WebService 方法的,最 ...
- 利用CSS制作背景变色的横向导航栏
1.表单 页面如下: <html> <head> <title>注册表单页面</title> </head> <body> &l ...
- linux操作提示:“Can't open file for writing”或“operation not permitted”的解决办法
在linux上使用vi命令修改一个文件内容的时候,发现无法保存,每次写完使用":q!"命令可以正常退出但是使用":wq!"命令保存文件并退出时出现一下信息提示: ...