Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Stack;
- public class Parantes {
- Stack<Character> stack = new Stack<Character>();
- int tal;
- String kod;{
- // Iterate over the characters in the forward direction
- for (int j = 0; j < tal; j++){
- for (int i = 0; i < kod.length();) {
- if (kod.charAt(i) == '(' || kod.charAt(i) == '[' || kod.charAt(i) == '{'){
- stack.push(kod.charAt(i));
- }
- else if (kod.charAt(i) == ')' || kod.charAt(i) == ']' || kod.charAt(i) == '}'){
- if (stack.peek() == '(' && kod.charAt(i) == ')'){
- stack.pop();
- }
- else if (stack.peek() == '{' && kod.charAt(i) == '}'){
- stack.pop();
- }
- else if (stack.peek() == '[' && kod.charAt(i) == ']'){
- stack.pop();
- }
- else{
- System.out.println("No");
- break;
- }
- }
- System.out.println("Yes");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment