0
点赞
收藏
分享

微信扫一扫

LeetCode力扣 125. 验证回文串 Valid Palindrome 题解代码 JavaScript


问题 ​​https://leetcode-cn.com/problems/valid-palindrome/​​

练习使用JavaScript解答

/**
* @param {string} s
* @return {boolean}
*/
function judgeChar(c) {
if(c >= '0' && c <= '9')
return true;
if(c >= 'a' && c <= 'z')
return true;
return false;
}

var isPalindrome = function(s) {
if(!s)
return true;
s = s.toLowerCase();
var i=0,j=s.length-1;
while(i<j) {
if(!judgeChar(s[i])) {
++i;
continue;
}
if(!judgeChar(s[j])) {
--j;
continue;
}
if(s[i] != s[j])
return false;
++i;
--j;
}
return true;
};

 

举报

相关推荐

0 条评论