public class Solution {
public int MaxDepth(string s) {
int depth = 0;
int maxDepth = 0;
foreach (var c in s) {
if (c == '(') {
++depth;
} else if (c == ')') {
--depth;
}
if (depth > maxDepth) {
maxDepth = depth;
}
}
return maxDepth;
}
}
Source: https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/
No comments:
Post a Comment