给定栈的压入序列判断栈的弹出序列是否合法
附上动图,一看就会
代码在此:
class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> stack =new Stack<>();
int i =0;
for(int num:pushed){
stack.push(num);
while(!stack.isEmpty() && stack.peek()==popped[i]){
stack.pop();
i++;
}
}
return stack.isEmpty();
}
}
今日才来打卡!
五一放假玩耍了4天!!!
钉钉网课时代假中假余额不足!!!