921. Minimum Add to Make Parentheses Valid
![17368230-7b6c2aefc71bd847.png](https://upload-images.jianshu.io/upload_images/17368230-7b6c2aefc71bd847.png)
921. Minimum Add to Make Parentheses Valid
class Solution(object):
def minAddToMakeValid(self, S):
"""
:type S: str
:rtype: int
"""
stack = []
for i in S:
if i == "(":
stack.append(i)
else:
if not stack or stack[-1] != "(":
stack.append(i)
else:
stack.pop()
return len(stack)