C++ 0ms faster than 100%
Whenever we get open bracket we will increase count by 1 and when we get close bracket we will decrease count by 1. But If our count becomes less than 0 than we
Whenever we get open bracket we will increase count by 1 and when we get close bracket we will decrease count by 1. But If our count becomes less than 0 than we have to add open bracket before current position so just absolute value of count and make count 0. Now at last we will add count to ans as we have to close all opened bracket.\n\n```\nclass Solution {\npublic:\n    int minAddToMakeValid(string s) {\n        int cnt = 0,ans = 0;\n        \n        for(int i =0;i<s.length();i++){\n            if(s[i]==\'(\')cnt++;\n            else cnt--;\n            if(cnt<0){ans+=abs(cnt);cnt=0;}\n        }\n        ans+=abs(cnt); \n        \n        return ans;\n    }\n};\n\n```
[]