🔥✅ Java | 100% faster | easy looping solution 🔥✅
Intuition\nIt\'s about balancing parentheses. Whenever a closing parenthesis is encountered, it should be balanced; otherwise, insert an opening parenthesis bef
# Intuition\nIt\'s about balancing parentheses. Whenever a closing parenthesis is encountered, it should be balanced; otherwise, insert an opening parenthesis before it. At the end, if there are any unclosed opening parentheses, close all of them.\n\n# Approach\n1. Keep a variable bracket to keep track of the number of opening and closing paranthesis\n2. Iterate through the loop and see if bracket is less than zero which is unbalanced and add the result\n3. Add the excess open brackets which are not closed to result and return it.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int minAddToMakeValid(String s) {\n        int bracket = 0,len = s.length(), res=0;\n        for(int i=0; i<len; i++){\n            if(s.charAt(i)==\'(\'){\n                bracket++;\n            } else{\n                bracket--;\n            }\n            if(bracket<0){\n                res++;\n                bracket++;\n            }\n        }\n        return res+bracket;\n    }\n}\n```
['Greedy', 'Java']