Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CheckParentheses {
- 9 public boolean check(String input) {
- 10 TrakStack a = new TrakStack();
- 11 char L1 = '(';
- 12 char L2 = '{';
- 13 char L3 = '[';
- 14 char R1 = ')';
- 15 char R2 = '}';
- 16 char R3 = ']';
- 17 for (char current: input.toCharArray()){
- 18 if (current == L1 || current == L2 || current == L3){
- 19 a.push(current);
- 20 }
- 21 if (current == R1){
- 22 if (a.pop() != L1){
- 23 return false;
- 24 }
- 25 }
- 26 if (current == R2){
- 27 if (a.pop() != L2){
- 28 return false;
- 29 }
- 30 }
- 31 if (current == R3){
- 32 if (a.pop() != L3){
- 33 return false;
- 34 }
- 35 }
- 36 }
- 37 return true;
- 38 }
- 39
- 40 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement