Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int minAddToMakeValid(String s) {
- Stack<Character>stack = new Stack<>();
- for(char c : s.toCharArray()){
- if(c=='('){
- stack.push(c);
- }else if(c == ')' && !stack.isEmpty() && stack.peek()=='('){
- stack.pop();
- }else{
- stack.push(c);
- }
- }
- return stack.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement