给定一个只包含括号的字符串,判断字符串是否有效。其中,括号种类包含: ‘(’,’)’,’{’,’}’,’[’,’]'。有效字符串需满足:1) 左括号必须用相同类型的右括号闭合;2)左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串
示例1
输入
"{[]}"
输出
true
示例2
输入
"([)]"
输出
false
示例3
输入
"([]"
输出
false
加载中...
import java.util.*; public class Solution { /** * * @param s string字符串 * @return bool布尔型 */ public boolean IsValidExp (String s) { // write code here } }
class Solution { public: /** * * @param s string字符串 * @return bool布尔型 */ bool IsValidExp(string s) { // write code here } };
# # # @param s string字符串 # @return bool布尔型 # class Solution: def IsValidExp(self , s ): # write code here
/** * * @param s string字符串 * @return bool布尔型 */ function IsValidExp( s ) { // write code here } module.exports = { IsValidExp : IsValidExp };
# # # @param s string字符串 # @return bool布尔型 # class Solution: def IsValidExp(self , s ): # write code here
package main /** * * @param s string字符串 * @return bool布尔型 */ func IsValidExp( s string ) bool { // write code here }
/** * * @param s string字符串 * @return bool布尔型 */ bool IsValidExp(char* s ) { // write code here }
"{[]}"
true
"([)]"
false
"([]"
false