MCPcopy Create free account
hub / github.com/MisterBooo/LeetCodeAnimation / Solution

Class Solution

problems/0946--validate-stack-sequences/Code/1.java:1–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public boolean validateStackSequences(int[] pushed, int[] popped) {
3
4 int N = pushed.length;
5 Stack<Integer> stack = new Stack();
6
7 int j = 0;
8 for (int x: pushed) {
9 stack.push(x);
10 while (!stack.isEmpty() && j < N && stack.peek() == popped[j]) {
11 //��ͷԪ�س��ӣ�ջ��Ԫ�س�ջ
12 stack.pop();
13 j++;
14 }
15 }
16 if (!stack.isEmpty()){
17 return false;
18 }
19 return true;
20 }
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected