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
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
说明:本题中,我们将空字符串定义为有效的回文串。
示例 1:
输入: "A man, a plan, a canal: Panama" 输出: true 示例 2:
输入: "race a car" 输出: false
解法 “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。 先过滤 再 反转后 跟原字符对比
/** * @param {string} s * @return {boolean} */ var isPalindrome = function(s) { let str=s.toLowerCase().replace(/[^a-z0-9]/g,''); //过滤 let re=str.split('').reverse().join(''); // 反转 return str===re };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
说明:本题中,我们将空字符串定义为有效的回文串。
示例 1:
输入: "A man, a plan, a canal: Panama"
输出: true
示例 2:
输入: "race a car"
输出: false
解法
“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。
先过滤 再 反转后 跟原字符对比
The text was updated successfully, but these errors were encountered: