2021年9月16日22:49:56
2021年9月16日23:20:04
模拟栈的操作 每次都要入栈 然后对比 看看能否出栈
最后看栈是否为空
import java.util.*;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
Stack<Integer> stack = new Stack<>();
int cur = 0;
for(int num: pushA){
stack.push(num);
while(!stack.empty() && stack.peek()==popA[cur]) {stack.pop();cur++;}
}
if(stack.empty()) return true;
else return false;
}
}



京公网安备 11010502036488号