Deque<String> deque = newLinkedList<>(); for (inti=0;i<s.length();i++){ deque.offerLast(s.substring(i,i+1)); if (deque.peekLast().equals(")")){ if (deque.size()==1){return"No";} deque.pollLast(); if (deque.peekLast().equals("(")){deque.removeLast();} else {return"No";} } elseif(deque.peekLast().equals("]")){ if (deque.size()==1){return"No";} deque.pollLast(); if (deque.peekLast().equals("[")){deque.removeLast();} else {return"No";} } } if (deque.size()==0){return"Yes";}else {return"No";} } }