楚雄市建设规划批前公示在那个网站,怎么做链接有图和文字,自己有网站怎么做竞价,海城建设网站给定一个只包括 (#xff0c;)#xff0c;{#xff0c;}#xff0c;[#xff0c;] 的字符串 s #xff0c;判断字符串是否有效。 有效字符串需要满足#xff1a; 左括号必须用相同类型的右括号闭合。例如#xff1a;[],(),{} 左括… 给定一个只包括 (){}[] 的字符串 s 判断字符串是否有效。 有效字符串需要满足 左括号必须用相同类型的右括号闭合。例如[],(),{} 左括号必须以正确的顺序闭合。例如[()] 每个右括号都有一个对应的相同类型的左括号。例如[()]{} package learnProject.csdn;/*** * author Roc-xb**/
public class ValidParentheses {public static boolean isValid(String s) {if (s null || s.length() 0)return false;char[] stack new char[s.length()];int head 0;for (char c : s.toCharArray()) {switch (c) {case {:case [:case (:stack[head] c;break;case }:if (head 0 || stack[--head] ! {) {return false;}break;case ):if (head 0 || stack[--head] ! () {return false;}break;case ]:if (head 0 || stack[--head] ! [) {return false;}break;}}return head 0;}public static void main(String[] args) {System.out.println(isValid(null));}
}