Python Solution
IntuitionStack :)ApproachJust go through the string. If "(" comes, add it to the stack. In case of ")", if the stack is empty or the previous element is also ")
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Stack :)
# Approach
<!-- Describe your approach to solving the problem. -->
Just go through the string. If "(" comes, add it to the stack. In case of ")", if the stack is empty or the previous element is also ")", add it to the stack. And if not, just pop the last element cause it has to be a "(". Finally return the length of the stack.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(N)
# Code
```python3 []
class Solution:
    def minAddToMakeValid(self, s: str) -> int:
        s2 = []
        for i in s:
            if i == "(":
                s2.append("(")
            elif i == ")" and (s2 == [] or s2[-1] == ")"):
                s2.append(")")
            else:
                s2.pop()
        return len(s2)
```
['Python3']