标签:return for character als [] array else public nbsp
用stack
1 class Solution { 2 public boolean isValid(String s) { 3 Stack<Character> stack = new Stack<Character>(); 4 char[] arr = s.toCharArray(); 5 for(char c : arr) { 6 if(c == ‘(‘) { 7 stack.push(‘)‘); 8 }else if(c == ‘{‘) { 9 stack.push(‘}‘); 10 }else if(c == ‘[‘) { 11 stack.push(‘]‘); 12 }else if(stack.isEmpty() || stack.pop() != c) { 13 return false; 14 } 15 } 16 return stack.isEmpty(); 17 18 } 19 }
标签:return for character als [] array else public nbsp
原文地址:https://www.cnblogs.com/goPanama/p/9545888.html