Skip to content

Instantly share code, notes, and snippets.

@guolinaileen
Last active December 11, 2015 14:38
Show Gist options
  • Save guolinaileen/4614990 to your computer and use it in GitHub Desktop.
Save guolinaileen/4614990 to your computer and use it in GitHub Desktop.
public class Solution {
public boolean isPalindrome(String str) {
// Start typing your Java solution below
// DO NOT write main() function
str=str.toLowerCase();
int start=0, end=str.length()-1;
while(start<=end)
{
if(start<=end && outOfRange(str.charAt(start)))
{
start++; continue;
}
if(start<=end && outOfRange(str.charAt(end)))
{
end--; continue;
}
if(str.charAt(start)!=str.charAt(end))
{
return false;
}
start++;
end--;
}
return true;
}
boolean outOfRange(char temp)
{
if(temp>='0'&&temp<='9') return false;
if(temp<'a') return true;
if(temp>'z') return true;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment