Maximum Nesting Depth of the Parentheses LeetCode solution in Java

1
class Solution {
2
public int maxDepth(String s) {
3
int count = 0; // count current dept of "()"
4
int max = 0; // count max dept of "()"
5

6
for (int i = 0; i < s.length(); i++) {
7
if (s.charAt(i) == '(') {
8
count++;
9
} else if (s.charAt(i) == ')') {
10
count--;
11
}
12
max = Math.max(count, max);
13
}
14
return max;
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0