1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/验证栈序列 [validate-stack-sequences].html
2022-03-29 12:43:11 +08:00

34 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定&nbsp;<code>pushed</code>&nbsp;&nbsp;<code>popped</code>&nbsp;两个序列,每个序列中的 <strong>值都不重复</strong>,只有当它们可能是在最初空栈上进行的推入 push 和弹出 pop 操作序列的结果时,返回 <code>true</code>;否则,返回 <code>false</code>&nbsp;</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>
<ul>
<li><code>1 &lt;= pushed.length &lt;= 1000</code></li>
<li><code>0 &lt;= pushed[i] &lt;= 1000</code></li>
<li><code>pushed</code> 的所有元素 <strong>互不相同</strong></li>
<li><code>popped.length == pushed.length</code></li>
<li><code>popped</code><code>pushed</code> 的一个排列</li>
</ul>