[Java] Both runtime and memory beats 100.00% submissions
\nclass Solution {\n    public String minRemoveToMakeValid(String s) {\n\n        char[] arr = s.toCharArray();\n        int open = 0;\n\n        for (int i = 0
```\nclass Solution {\n    public String minRemoveToMakeValid(String s) {\n\n        char[] arr = s.toCharArray();\n        int open = 0;\n\n        for (int i = 0; i < arr.length; i++) {\n            if (arr[i] == \'(\')\n                open++;\n            else if (arr[i] == \')\') {\n                if (open == 0)\n                    arr[i] = \'*\';\n                else\n                    open--;\n            }\n        }\n\n        for (int i = arr.length - 1; i >= 0; i--) {\n            if (open > 0 && arr[i] == \'(\') {\n                arr[i] = \'*\';\n                open--;\n            }\n        }\n\n        int p = 0;\n        for (int i = 0; i < arr.length; i++) {\n            if (arr[i] != \'*\')\n                arr[p++] = arr[i];\n        }\n\n        return new String(arr).substring(0, p);\n    }\n}\n```
['Java']