|
2 | 2 |
|
3 | 3 | importjava.util.Stack;
|
4 | 4 |
|
5 |
| -/** |
6 |
| - * 946. Validate Stack Sequences |
7 |
| - * |
8 |
| - * Given two sequences pushed and popped with distinct values, |
9 |
| - * 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. |
10 |
| - * |
11 |
| - * Example 1: |
12 |
| - * Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1] |
13 |
| - * Output: true |
14 |
| - * Explanation: We might do the following sequence: |
15 |
| - * push(1), push(2), push(3), push(4), pop() -> 4, |
16 |
| - * push(5), pop() -> 5, pop() -> 3, pop() -> 2, pop() -> 1 |
17 |
| - * |
18 |
| - * Example 2: |
19 |
| - * Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2] |
20 |
| - * Output: false |
21 |
| - * Explanation: 1 cannot be popped before 2. |
22 |
| - * |
23 |
| - * Note: |
24 |
| - * 0 <= pushed.length == popped.length <= 1000 |
25 |
| - * 0 <= pushed[i], popped[i] < 1000 |
26 |
| - * pushed is a permutation of popped. |
27 |
| - * pushed and popped have distinct values. |
28 |
| - * */ |
29 | 5 | publicclass_946 {
|
30 | 6 | publicstaticclassSolution1 {
|
31 | 7 | publicbooleanvalidateStackSequences(int[]pushed,int[]popped) {
|
|