~8ms🔰Unable to beats100% ||BUT||😔 only 97.%~  |🔰| JAVA USERS🔰Parentheses Removal Approach 🔰
By employing this two-pass optimization technique and directly modifying the input string, the code achieves efficient removal of parentheses while minimizing m
> By employing this two-pass optimization technique and directly modifying the input string, the code achieves efficient removal of parentheses while minimizing memory usage and runtime overhead.\n![\n![Screenshot 2024-04-06 072052.png](https://assets.leetcode.com/users/images/45379aa9-124f-415f-9796-22208756fa74_1712368296.9642086.png)\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public String minRemoveToMakeValid(String s) {\n        char[] chars = s.toCharArray();\n        int openCount = 0;\n        \n        // Forward pass: mark invalid closing parentheses and count open parentheses\n        for (int i = 0; i < chars.length; i++) {\n            char c = chars[i];\n            if (c == \'(\') {\n                openCount++;\n            } else if (c == \')\') {\n                if (openCount == 0) {\n                    chars[i] = \'*\'; // Mark invalid closing parenthesis\n                } else {\n                    openCount--;\n                }\n            }\n        }\n        \n        // Backward pass: mark extra open parentheses\n        for (int i = chars.length - 1; i >= 0 && openCount > 0; i--) {\n            if (chars[i] == \'(\') {\n                chars[i] = \'*\'; // Mark extra open parenthesis\n                openCount--;\n            }\n        }\n        \n        // Construct result string\n        StringBuilder result = new StringBuilder();\n        for (char c : chars) {\n            if (c != \'*\') {\n                result.append(c);\n            }\n        }\n        \n        return result.toString();\n    }\n}\n\n\n```
['Java']