1614. Maximum Nesting Depth of the Parentheses
in Coding Interview on String, Stack
괄호의 최대 중첩 깊이
class Solution {
// 괄호의 최대 중첩 깊이
// T: O(n)
public int maxDepth(String s) {
int res = 0;
int depth = 0;
for (int i = 0; i < s.length(); ++i) {
if (s.charAt(i) == '(') {
res = Math.max(res, ++depth);
} else if (s.charAt(i) == ')') {
depth--;
}
}
return res;
}
}