[Java] 100% [O(N) TC ][O(1) SC] || With Explanation
Please upvote if you like the solution !!\n# Intuition\n Describe your first thoughts on how to solve this problem. \n- If the symbol is \'(\' just increase the
# Please upvote if you like the solution !!\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- If the symbol is **\'(\'** just increase the count of **open** variable by 1.\n- If the symbol is **\')\'** check whether it\'s pair there or not. \n- If **open** variable is greater than zero we have the pair then decrement the count of **open** if not increase the **count** value by 1.\n- At last check **open** variable is greater than zero if it is then add to **count** variable.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\n# Code\n```\nclass Solution {\n    public int minAddToMakeValid(String s) {\n      int open = 0;\n       int count = 0;\n       for(char c : s.toCharArray()) {\n           if(c == \'(\') {\n               open++;\n            }\n           else if(c == \')\') {\n               if(open > 0) open--;\n               else count++;\n           }\n        }\n       count += open;\n\n       return count;\n    }\n}\n```
['Java']