blob: 49bd8f5a6ea9a3121e1e98e5a530d56060c146d6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
// 1614. Maximum Nesting Depth of the Parentheses
#include "leetcode.h"
int maxDepth(char *s) {
int ans = 0, k = 0, n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] == '(')
k++;
if (s[i] == ')')
k--;
if (k > ans)
ans = k;
}
return ans;
}
int main() {
char *s1 = "(1+(2*3)+((8)/4))+1", *s2 = "(1)+((2))+(((3)))";
printf("%d\n", maxDepth(s1)); // expect: 3
printf("%d\n", maxDepth(s2)); // expect: 3
}
|