题解 | #栈的压入、弹出序列#

栈的压入、弹出序列

http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106

import java.util.ArrayList;
import java.util.Arrays;

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        //模拟入栈出栈
        int curPush = 0;
        int curPop = 0;
        for(int i = 0; i < pushA.length; i++){
            pushA[curPush] = pushA[i];
            while(curPush>=0 && pushA[curPush] == popA[curPop]){
                curPop++;
                curPush--;
            }
            curPush++;
        }
        return curPush == 0;
    }
    
}

全部评论

相关推荐

优秀的大熊猫在okr...:多益:此贼,必有同谋,按律,该当连坐!
你不能接受的企业文化有哪...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务