zoukankan      html  css  js  c++  java
  • 水王

    package demo;

    import java.util.Stack;

    public class Test {

        public static void main(String[]args)

        {

            String[] a ={"a","b","a","a","a","c","b"};

            String shuiwang=select(a);

            System.out.println("水王是"+shuiwang);;

        }

        static String select(String[] a)

        {

            Stack<String> s =new Stack<String>();

            s.push("#");

            for(int i=0;i<a.length;i++)

            {

                if(a[i].equals(s.peek())||s.peek().equals("#"))

                {

                    s.push(a[i]);

                }

                else

                {

                    s.pop();

                }

            }

            String rs=s.pop();

            return rs;

        }

    }

    截图:

    package demo;

    import java.util.Stack;

    public class Test {

        public static void main(String[]args)

        {

            String[] a ={"a","b","a","a","a","c","b"};

            String shuiwang=select(a);

            System.out.println("水王是"+shuiwang);;

        }

        static String select(String[] a)

        {

            Stack<String> s =new Stack<String>();

            s.push("#");

            for(int i=0;i<a.length;i++)

            {

                if(a[i].equals(s.peek())||s.peek().equals("#"))

                {

                    s.push(a[i]);

                }

                else

                {

                    s.pop();

                }

            }

            String rs=s.pop();

            return rs;

        }

    }

    截图:

     

  • 相关阅读:
    spring websocket 记录
    mysql-enum
    再问jvm内存管理
    video相关参数、操作和事件
    监听页面关闭和刷新的总结
    VUE路由新页面打开的方法总结
    VUE的一个数据绑定与页面刷新相关的bug
    element-ui笔记
    Vue笔记(props和 mounted)
    Python总结(二)
  • 原文地址:https://www.cnblogs.com/jokerr/p/7019515.html
Copyright © 2011-2022 走看看