Minimum Add to Make Parentheses Valid LeetCode solution in Python

1
class Solution:
2
def minAddToMakeValid(self, s: str) -> int:
3
l, r = list(), list()
4
for i in s:
5
if i == "(":
6
l.append(i)
7
else:
8
if l:
9
l.pop()
10
else:
11
r.append(i)
12
return len(l) + len(r)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0