My solution beats 100% . simple solution in c++
Intuition \uD83C\uDFAF\n Describe your first thoughts on how to solve this problem. \nThis problem focuses on finding the minimum number of parentheses addition
# Intuition \uD83C\uDFAF\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem focuses on finding the minimum number of parentheses additions needed to make a string of parentheses (( and )) valid. A valid string of parentheses is one where every opening parenthesis (() has a corresponding closing parenthesis ()), and the pairs are properly nested.\n\nThe key idea here is to use a stack to track unmatched parentheses:\n\n<ul><li>If we encounter an opening parenthesis ((), we push it onto the stack.</li>\n<li>If we encounter a closing parenthesis ()), we check the top of the stack:</li></ul>\n<li>If the top is an unmatched opening parenthesis ((), we can form a valid pair, so we pop it.</li>\n<li>Otherwise, we push the closing parenthesis onto the stack as it is unmatched.</li></ul></ul>\nBy the end of the traversal, the stack will contain any unmatched parentheses, and the size of the stack will be the number of parentheses that need to be added to make the string valid.\n\n# Approach \uD83D\uDEB6\u200D\u2642\uFE0F\n<!-- Describe your approach to solving the problem. -->\n1. Stack Usage \uD83E\uDDEE:\n\n<ul><li>Traverse the string character by character.</li>\n<li>If the stack is not empty and the top of the stack is an unmatched opening parenthesis ((), and the current character is a closing parenthesis ()), pop the stack (this indicates a valid pair).</li>\n<li>Otherwise, push the current character (either ( or )) onto the stack.</li></ul>\n2. Unmatched Parentheses Count \uD83D\uDD04:\n\n<ul><li>By the end of the traversal, the stack will contain only unmatched parentheses (both ( and )).</li><li>\nThe size of the stack will give the total number of unmatched parentheses, and this is the minimum number of parentheses to add to make the string valid.</li></ul>\n3. Return Result \uD83C\uDFC1:\n\n<ul><li>The function returns the size of the stack, which represents the number of additions needed.</li></ul>\n\n4. Example \uD83D\uDCA1\nConsider the input string s = "())(":\n\n<li><ul>First ) matches with the first (, so the pair is valid and removed from the stack.</li>\n<li>The second ) is unmatched, so it\'s pushed onto the stack.</li>\n<li>The last ( is unmatched, so it also stays on the stack.</li>\n<li>In the end, the stack contains ) and (, which means we need to add 2 parentheses to balance them. The result is 2.</li></ul>\n# Complexity \uD83D\uDCCA\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(n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    \n    int minAddToMakeValid(string s) {\n        stack<char> stac;\n        for(char c : s)\n        {\n            if(!stac.empty() && stac.top()==\'(\' && c==\')\')stac.pop();\n            else stac.push(c);\n        }\n        return stac.size();\n    }\n};\n```
['Stack', 'C++']