MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / minAddToMakeValid

Method minAddToMakeValid

String/MinimumAddToMakeParenthesesValid.py:46–66  ·  view source on GitHub ↗

:type S: str :rtype: int

(self, S)

Source from the content-addressed store, hash-verified

44"""
45class Solution(object):
46 def minAddToMakeValid(self, S):
47 """
48 :type S: str
49 :rtype: int
50 """
51 if not S:
52 return 0
53 t = [S[0]]
54 for i in S[1:]:
55 if i == ')':
56 if not t:
57 t.append(i)
58 continue
59
60 if t[-1] == '(':
61 t.pop()
62 else:
63 t.append(i)
64 else:
65 t.append(i)
66 return len(t)
67

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected