这道题就是921的变种,话不多说:

    public int maxDepth(String s) {
        int count = 0;
        int max = 0;
        for (char c : s.toCharArray()) {
            if (c == '(') {
                count++;
                max = Math.max(max, count);
            } else if (c == ')') {
                count--;
            }
        }
        return max;
    }

 

posted on 2022-02-02 03:12  阳光明媚的菲越  阅读(26)  评论(0编辑  收藏  举报