代码拉取完成,页面将自动刷新
package com.fishercoder.solutions;
/**
* 125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,
"A man, a plan, a canal: Panama" is a palindrome.
"race a car" is not a palindrome.
Note:
Have you consider that the string might be empty? This is a good question to ask during an interview.
For the purpose of this problem, we define empty string as valid palindrome.
*/
public class _125 {
public static class Solution1 {
public boolean isPalindrome(String s) {
int i = 0;
int j = s.length() - 1;
char[] chars = s.toCharArray();
while (i < j) {
while (i < j && !Character.isLetterOrDigit(chars[i])) {
i++;
}
while (i < j && !Character.isLetterOrDigit(chars[j])) {
j--;
}
if (Character.toLowerCase(chars[i]) != Character.toLowerCase(chars[j])) {
return false;
}
i++;
j--;
}
return true;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。