package
Version:
v0.0.0-...-b071cee
Opens a new window with list of versions in this module.
Published: Aug 9, 2023
License: GPL-3.0
Opens a new window with license information.
Imports: 0
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
有效的括号
1.题目描述
给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。
有效字符串需满足:
左括号必须用相同类型的右括号闭合。
左括号必须以正确的顺序闭合。
2.示例
提示:
1 <= s.length <= 104
s 仅由括号 '()[]{}' 组成
示例 1:
输入:s = "()"
输出:true
示例 2:
输入:s = "()[]{}"
输出:true
示例 3:
输入:s = "(]"
输出:false
示例 4:
输入:s = "([)]"
输出:false
示例 5:
输入:s = "{[]}"
输出:true
3. 解题
1.若字符串为空,则判为有效
2.若不为空,遍历字符串,若遇到左括号,则将其对应的右括号压入栈中;下一个为右括号且与栈顶匹配,则有效
3.最后判断栈是否为空
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.