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
给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。
'('
')'
'{'
'}'
'['
']'
有效字符串需满足:
注意空字符串可被认为是有效字符串。
Input: "()" Output: true
Input: "()[]{}" Output: true
Input: "(]" Output: false
Input: "([)]" Output: false
Input: "{[]}" Output: true
The text was updated successfully, but these errors were encountered:
/** * @param {string} s * @return {boolean} */ var isValid = function(s) { const stack = []; for (let i = 0; i < s.length; i++) { if (s[i] === '(' || s[i] === '[' || s[i] === '{') { stack.push(s[i]); continue; } const part = stack.pop(); if ( part === '(' && s[i] === ')' || part === '[' && s[i] === ']' || part === '{' && s[i] === '}' ) { continue; } return false; } return stack.length === 0; };
function isValid(s: string): boolean { const stack: string[] = []; for (let i = 0; i < s.length; i++) { if (s[i] === '(' || s[i] === '[' || s[i] === '{') { stack.push(s[i]); continue; } const part = stack.pop(); if ( part === '(' && s[i] === ')' || part === '[' && s[i] === ']' || part === '{' && s[i] === '}' ) { continue; } return false; } return stack.length === 0; };
Sorry, something went wrong.
No branches or pull requests
20. Valid Parentheses
给定一个只包括
'('
,')'
,'{'
,'}'
,'['
,']'
的字符串,判断字符串是否有效。有效字符串需满足:
注意空字符串可被认为是有效字符串。
Example 1
Example 2
Example 3
Example 4
Example 5
The text was updated successfully, but these errors were encountered: