1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/栈的压入、弹出序列 [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html

32 lines
1.3 KiB
HTML
Raw Normal View History

2022-03-27 20:38:29 +08:00
<p>输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如,序列 {1,2,3,4,5} 是某栈的压栈序列,序列 {4,5,3,2,1} 是该压栈序列对应的一个弹出序列,但 {4,3,5,1,2} 就不可能是该压栈序列的弹出序列。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
<strong>输出:</strong>true
<strong>解释:</strong>我们可以按以下顺序执行:
push(1), push(2), push(3), push(4), pop() -&gt; 4,
push(5), pop() -&gt; 5, pop() -&gt; 3, pop() -&gt; 2, pop() -&gt; 1
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
<strong>输出:</strong>false
<strong>解释:</strong>1 不能在 2 之前弹出。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ol>
<li><code>0 &lt;= pushed.length == popped.length &lt;= 1000</code></li>
<li><code>0 &lt;= pushed[i], popped[i] &lt; 1000</code></li>
<li><code>pushed</code>&nbsp;&nbsp;<code>popped</code>&nbsp;的排列。</li>
</ol>
<p>注意:本题与主站 946 题相同:<a href="https://leetcode-cn.com/problems/validate-stack-sequences/">https://leetcode-cn.com/problems/validate-stack-sequences/</a></p>