diff --git a/Python Solutions/D21P2_LeetCode_921.py b/Python Solutions/D21P2_LeetCode_921.py index 8b3de34..a83aac1 100644 --- a/Python Solutions/D21P2_LeetCode_921.py +++ b/Python Solutions/D21P2_LeetCode_921.py @@ -1 +1,13 @@ -# Python3 code coming soon \ No newline at end of file +class Solution: + def minAddToMakeValid(self, s: str) -> int: + stack = [] + count = 0 + for ch in s: + if ch == '(': + stack.append(ch) + else: + if stack and stack[-1] == '(': + stack.pop() + else: + count += 1 + return count+len(stack)