Maximum Nesting Depth of the Parentheses
给一个算式, 求最深的括号的个数.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
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; } } |