您的位置:首页 > 其它

[LeetCode]125 Valid Palindrome

2015-01-07 15:02 375 查看
https://oj.leetcode.com/problems/valid-palindrome/
http://blog.csdn.net/linhuanmars/article/details/22775045
public class Solution {
public boolean isPalindrome(String s) {
{
if (s == null)
return false;

if (s.isEmpty())
return true;

char[] chars = s.toLowerCase().toCharArray();
int indexL = 0;
int indexR = chars.length - 1;

while (indexL < indexR)
{
char cL = chars[indexL];
if (ignore(cL))
{
indexL ++;
continue;
}

char cR = chars[indexR];
if (ignore(cR))
{
indexR --;
continue;
}

if (cL != cR)
{
return false;
}

indexL ++;
indexR --;
}
return true;
}

private boolean ignore(char c)
{
return !((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LeetCode