[JAVA] [0MS] [100%] [STACK]
```\nclass Solution {\n    public int minAddToMakeValid(String S) {\n         int res = 0;\n       Stack stack = new Stack<>();\n       for(char c : S.toCharArr
```\nclass Solution {\n    public int minAddToMakeValid(String S) {\n         int res = 0;\n       Stack<Character> stack = new Stack<>();\n       for(char c : S.toCharArray()){\n           if(c == \'(\'){\n               stack.push(c);\n           }\n           else{\n               if(stack.empty())\n                   res++;\n               else\n                   stack.pop();\n           }\n       }\n       return res+stack.size();\n    }\n}
['Stack', 'Java']