We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 简单
Related Topics: 栈, 字符串
给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。
'('
')'
'{'
'}'
'['
']'
s
有效字符串需满足:
示例 1:
输入:s = "()" 输出:true
示例 2:
输入:s = "()[]{}" 输出:true
示例 3:
输入:s = "(]" 输出:false
提示:
'()[]{}'
Language: JavaScript
/** * @param {string} s * @return {boolean} */ var isValid = function(s) { if (s.length % 2 !== 0) return false const map = { '(' : ')', '{' : '}', '[' : ']', } let stack = [] for (let char of s) { if (map[char]) { stack.push(map[char]) } else { let ret = stack.pop() if (ret !== char) { return false } } } return stack.length === 0 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
20. 有效的括号
Description
Difficulty: 简单
Related Topics: 栈, 字符串
给定一个只包括
'('
,')'
,'{'
,'}'
,'['
,']'
的字符串s
,判断字符串是否有效。有效字符串需满足:
示例 1:
示例 2:
示例 3:
提示:
s
仅由括号'()[]{}'
组成Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: