serega1112

921

Dec 23rd, 2020 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. class Solution:
  2.     def minAddToMakeValid(self, S: str) -> int:
  3.        
  4.         count = 0
  5.         res = 0
  6.         for c in S:
  7.             if c == '(':
  8.                 count += 1
  9.             elif count:
  10.                 count -= 1
  11.             else:
  12.                 res += 1
  13.                
  14.         return res + count
Add Comment
Please, Sign In to add comment