Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 449 Bytes

1614.md

File metadata and controls

21 lines (19 loc) · 449 Bytes

1614. Maximum Nesting Depth of the Parentheses

Solution 1 (time O(n), space O(1))

class Solution(object):
    def maxDepth(self, s):
        """
        :type s: str
        :rtype: int
        """
        cnt = 0
        ans = 0
        for c in s:
            if c == "(":
                cnt += 1
                ans = max(cnt, ans)
            elif c == ")":
                cnt -= 1
        return ans