Package Level2; import java. util. stack;/***** Valid Parentheses ** Given a string containing just the characters '(',')','{','}', '['and']', determine if the input string is valid. the brackets must close in the correct order, "()" and "() [] {}" are all valid but "(]" and "([)]" are not. **/public class S20 {public static void main (String [] args) {}// use stack to check public boolean isValid (String s) {Stack <Character> stack = new Stack <Character> (); for (int I = 0; I <s. length (); I ++) {char c = s. charAt (I); // press the Front Bracket into the stack if (c = '(' | c = '[' | c = '{') {stack. push (c);} else if (c = ')' | c = ']' | c = '}') {// if (stack. size () = 0) {// It indicates that there are too many parentheses. return false;} char cpop = stack. pop (); if (cpop = '(' & c = ') {continue ;} else if (cpop = '[' & c = ']') {continue;} else if (cpop = '{' & c = '}') {continue;} return false;} return stack. size () = 0 ;}}