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/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Thursday, February 18, 2021
Leetcode Everyday: 1614. Maximum Nesting Depth of the Parentheses. Easy
Labels:
leetcode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment