본문 바로가기
python-algorithm

Leetcode 1614. Maximum Nesting Depth of the Parentheses

by 무적김두칠 2021. 8. 31.

참고: leetcode r0bertz

1
2
3
4
5
6
7
8
9
class Solution:
    def maxDepth(self, s: str-> int:
        ans=cnt=0
        for i in s:
            if i =="(" : 
                cnt+=1
                ans=max(ans,cnt)
            elif i==")" : cnt-=1
        return ans
cs
반응형

댓글