Skip to content

Commit f390254

Browse files
committed
921
1 parent 8feca19 commit f390254

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# @lc app=leetcode id=921 lang=python3
3+
#
4+
# [921] Minimum Add to Make Parentheses Valid
5+
#
6+
7+
# @lc code=start
8+
class Solution:
9+
def minAddToMakeValid(self, S: str) -> int:
10+
left = right = 0
11+
for i in S:
12+
if right == 0 and i == ')':
13+
left += 1
14+
else:
15+
right += 1 if i == '(' else -1
16+
return left + right
17+
# @lc code=end
18+

0 commit comments

Comments
 (0)