Simple 3 lines Code (Easy Approach)
\n# Approach\n1. Keep count of open and close bracket. \n2. if \'(\' encounter increesed open and else if \')\' encounter and open is greater than 0 means 1 ope
\n# Approach\n1. Keep count of open and close bracket. \n2. if \'(\' encounter increesed open and else if \')\' encounter and open is greater than 0 means 1 open open bracket is already happens so decreesed open else increese close\n3. return open + close\n\n# Complexity\n- Time complexity:\nO(n);\n\n- Space complexity:\nO(1)\n\n# Code\n```java []\nclass Solution {\n    public int minAddToMakeValid(String s) {\n        int open= 0, close=0;\n        for(char c: s.toCharArray()){\n            if(c==\'(\') open++;\n            else if (c==\')\' && open>0) open--;\n            else close++;\n        }\n        return open+close;\n    }\n}\n```\n# Code\n```C++ []\nclass Solution {\npublic:\n    int minAddToMakeValid(string s) {\n        int open = 0, close = 0;\n        for (char c : s) {\n            if (c == \'(\') open++;\n            else if (c == \')\' && open > 0) open--;\n            else close++;\n        }\n        return open + close;\n    }\n};\n```\n# Code\n``` Python []\nclass Solution:\n    def minAddToMakeValid(self, s: str) -> int:\n        open, close = 0, 0\n        for c in s:\n            if c == \'(\':\n                open += 1\n            elif c == \')\' and open > 0:\n                open -= 1\n            else:\n                close += 1\n        return open + close\n```\n
['String', 'Greedy', 'Python', 'C++', 'Java']