给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。 左括号必须以正确的顺序闭合。
示例1
输入
"{[]}"
输出
true
备注:
无
加载中...
import java.util.*; public class Solution { /** * 判断是否满足条件 * @param s string字符串 字符串s * @return bool布尔型 */ public boolean isValid (String s) { // write code here } }
class Solution { public: /** * 判断是否满足条件 * @param s string字符串 字符串s * @return bool布尔型 */ bool isValid(string s) { // write code here } };
# # 判断是否满足条件 # @param s string字符串 字符串s # @return bool布尔型 # class Solution: def isValid(self , s ): # write code here
/** * 判断是否满足条件 * @param s string字符串 字符串s * @return bool布尔型 */ function isValid( s ) { // write code here } module.exports = { isValid : isValid };
# # 判断是否满足条件 # @param s string字符串 字符串s # @return bool布尔型 # class Solution: def isValid(self , s ): # write code here
"{[]}"
true