Advertisement
Guest User

Untitled

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