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;

        }

    }

    截图:

     

  • 相关阅读:
    调试相关blogs收集
    union和union all
    V$SQLAREA
    Oracle Access和filter的区别
    Oracle 复合索引设计原理——前缀性和可选性
    经济学原理---8应用:税收的代价--- 读书笔记
    经济学原理---7 消费者.生产者与市场效率--- 读书笔记
    经济学原理---6 供给.需求与政府政策--- 读书笔记
    经济学原理---5 弹性及其应用 --- 读书笔记
    CURL---常见问题
  • 原文地址:https://www.cnblogs.com/jokerr/p/7019515.html
Copyright © 2011-2022 走看看