Class Solution
java.lang.Object
g0901_1000.s0946_validate_stack_sequences.Solution
946 - Validate Stack Sequences.<p>Medium</p>
<p>Given two integer arrays <code>pushed</code> and <code>popped</code> each with distinct values, return <code>true</code> <em>if this could have been the result of a sequence of push and pop operations on an initially empty stack, or</em> <code>false</code> <em>otherwise.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> pushed = [1,2,3,4,5], popped = [4,5,3,2,1]</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> We might do the following sequence:</p>
<p>push(1), push(2), push(3), push(4),</p>
<p>pop() -> 4,</p>
<p>push(5),</p>
<p>pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> pushed = [1,2,3,4,5], popped = [4,3,5,1,2]</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> 1 cannot be popped before 2.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= pushed.length <= 1000</code></li>
<li><code>0 <= pushed[i] <= 1000</code></li>
<li>All the elements of <code>pushed</code> are <strong>unique</strong>.</li>
<li><code>popped.length == pushed.length</code></li>
<li><code>popped</code> is a permutation of <code>pushed</code>.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
validateStackSequences
public boolean validateStackSequences(int[] pushed, int[] popped)
-