Last active
December 11, 2015 14:38
-
-
Save guolinaileen/4614990 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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