Maximum Nesting Depth of the Parentheses LeetCode solution in C++

1
class Solution {
2
public:
3
int maxDepth(string s) {
4
int maxi = 0, curr = 0;
5
for (int i = 0; i < s.size(); i++) {
6
if (s[i] == '(') {
7
maxi = max(maxi, ++curr);
8
} else if (s[i] == ')') {
9
curr--;
10
}
11
}
12
return maxi;
13
}
14
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0