(String x)
| 25 | } |
| 26 | |
| 27 | static boolean ispar(String x) |
| 28 | { |
| 29 | // add your code here |
| 30 | Stack<Character> stack = new Stack<Character>(); |
| 31 | for(int i=0;i<x.length();i++) |
| 32 | { |
| 33 | if(opening(x.charAt(i))) |
| 34 | { |
| 35 | stack.push(x.charAt(i)); |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | if(stack.isEmpty()) return false; |
| 40 | if(!Matches(stack.peek(),x.charAt(i))) return false; |
| 41 | stack.pop(); |
| 42 | } |
| 43 | } |
| 44 | return stack.isEmpty(); |
| 45 | } |
| 46 | } |