Greedy string again||Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nGreedy string modifies the solution for  yesterday\'s daily question\n1963. Minimum Num
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGreedy string modifies the solution for  yesterday\'s daily question\n[1963. Minimum Number of Swaps to Make the String Balanced](https://leetcode.com/problems/minimum-number-of-swaps-to-make-the-string-balanced/solutions/5884212/greedy-string42-ms-beats-9957/)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Set `r=0, l=0` to denote the unbalanced number for `(`, `)`\n2. Use a loop to proceed:\n```\nfor (char c: s){\n    bool isLeft=(c==\'(\');\n    l+=isLeft;\n    (l>0)?l-=(!isLeft):r+=(!isLeft);\n}\n```\n3 `r+l` is the answer\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||0ms beats 100%\n```cpp []\nclass Solution {\npublic:\n    int minAddToMakeValid(string& s) {\n        int l=0, r=0;\n        for (char c: s){\n            bool isLeft=(c==\'(\');\n            l+=isLeft;\n            (l>0)?l-=(!isLeft):r+=(!isLeft);\n        }\n        return l+r;\n    }\n};\n```
['String', 'Greedy', 'C++']