当前位置:网站首页>2022.5.28-----leetcode. one thousand and twenty-one

2022.5.28-----leetcode. one thousand and twenty-one

2022-06-10 04:44:00 Lu 727

  public String removeOuterParentheses(String ss) {
        String ans="";
        Deque<Character> s=new ArrayDeque<>();
        for(int i=0;i<ss.length();i++){
            char ch=ss.charAt(i);
            if(ch=='('){
                if(!s.isEmpty()) ans+=ch;
                s.add(ch);
            }else{
                s.poll();
               if(!s.isEmpty()) ans+=ch;
            }
        }
        return ans;
    }

原网站

版权声明
本文为[Lu 727]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091228491862.html