题解 | #括号匹配深度#

括号匹配深度

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

图片说明

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        int count=0,res=0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='('){
                count++;
            }else{
                count--;
            }
            res=Math.max(res,count);
        }
        sc.close();
        System.out.println(res);
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-25 17:26
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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