题解 | #设计getMin功能的栈#

设计getMin功能的栈

http://www.nowcoder.com/practice/05e57ce2cd8e4a1eae8c3b0a7e9886be

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        Deque<Integer> data=new LinkedList<>();

        for(int i=0;i<=n;i++){
            String line=sc.nextLine();
            String[] strs=line.split(" ");

            String op=strs[0];

            if("push".equals(op)){
                data.addLast(Integer.parseInt(strs[1]));
            }else if("pop".equals(op)){
                data.removeLast();
            }else if("getMin".equals(op)){
                Integer[] ints=data.toArray(new Integer[0]);
                Arrays.sort(ints);
                System.out.println(ints[0]);
            }
        }
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 11:27
点赞 评论 收藏
分享
白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
06-07 17:17
嘉兴学院 教师
心爱的idea:你孩
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-03 18:22
投了几百份简历,专业和方向完全对口,都已读不回。尝试改了一下学校,果然有奇效。
steelhead:这不是很正常嘛,BOSS好的是即便是你学院本可能都会和聊几句,牛客上学院本机会很少了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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