# 1614. Maximum Nesting Depth of the Parentheses ###### tags: `Leetcode` `Bloomberg` `Parentheses` `Easy` `FaceBook` Link: https://leetcode.com/problems/maximum-nesting-depth-of-the-parentheses/ ## 思路 过于简单了 直接看code吧 ## Code ```python= class Solution: def maxDepth(self, s: str) -> int: maxScore = 0 currScore = 0 for i, c in enumerate(s): if c == '(': currScore += 1 maxScore = max(maxScore, currScore) elif c == ')': currScore -= 1 return maxScore ``` ```java= class Solution { public int maxDepth(String s) { int curr = 0; int ans = 0; for(int i = 0;i < s.length();i++){ if(s.charAt(i)=='('){ curr++; if(ans < curr) ans = curr; } else if(s.charAt(i)==')'){ curr--; } } return ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up