Created
December 20, 2014 07:50
-
-
Save wangchauyan/cd5bb5f1c8d95ea84e85 to your computer and use it in GitHub Desktop.
Valid a string is palindrome or not.
This file contains hidden or 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
package wcy.leetcode.gist; | |
/** | |
* Created by ChauyanWang on 12/20/14. | |
*/ | |
public class Valid_Palindrome { | |
public boolean Solution (String s) { | |
if( s == null || s.length() == 0) return true; | |
s = s.toLowerCase(); | |
int start = 0; | |
int end = s.length() -1; | |
while(start < end) { | |
if((s.charAt(start) < '0' || s.charAt(start) > '9') && | |
(s.charAt(start) < 'a' || s.charAt(start) > 'z')) { | |
start ++; | |
continue; | |
} | |
if((s.charAt(end) < '0' || s.charAt(end) > '9') && | |
(s.charAt(end) < 'a' || s.charAt(end) > 'z')) { | |
end --; | |
continue; | |
} | |
if(s.charAt(end) != s.charAt(start)) return false; | |
start++; | |
end --; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment