Maximum Nesting Depth of the Parentheses

给一个算式, 求最深的括号的个数.

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