mirror of
https://gitee.com/TheAlgorithms/LeetCodeAnimation.git
synced 2024-12-31 15:25:33 +08:00
21 lines
549 B
Java
21 lines
549 B
Java
|
class Solution {
|
|||
|
public boolean validateStackSequences(int[] pushed, int[] popped) {
|
|||
|
|
|||
|
int N = pushed.length;
|
|||
|
Stack<Integer> stack = new Stack();
|
|||
|
|
|||
|
int j = 0;
|
|||
|
for (int x: pushed) {
|
|||
|
stack.push(x);
|
|||
|
while (!stack.isEmpty() && j < N && stack.peek() == popped[j]) {
|
|||
|
//<2F><>ͷԪ<CDB7>س<EFBFBD><D8B3>ӣ<EFBFBD>ջ<EFBFBD><D5BB>Ԫ<EFBFBD>س<EFBFBD>ջ
|
|||
|
stack.pop();
|
|||
|
j++;
|
|||
|
}
|
|||
|
}
|
|||
|
if (!stack.isEmpty()){
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|