Created
September 14, 2017 18:47
-
-
Save cixuuz/6d5f357e765fa8ea9e71154b62f4cc4d to your computer and use it in GitHub Desktop.
[125. Valid Palindrome] #leetcode
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
| class Solution { | |
| public boolean isPalindrome(String s) { | |
| if (s.length() == 0) return true; | |
| StringBuilder validLetters = new StringBuilder(); | |
| for (Character c : s.toCharArray()) { | |
| if (Character.isLetter(c) || Character.isDigit(c)) { | |
| validLetters.append(Character.toLowerCase(c)); | |
| } | |
| } | |
| return validLetters.toString().equals(validLetters.reverse().toString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment