Skip to content

Instantly share code, notes, and snippets.

@cixuuz
Created September 14, 2017 18:47
Show Gist options
  • Select an option

  • Save cixuuz/6d5f357e765fa8ea9e71154b62f4cc4d to your computer and use it in GitHub Desktop.

Select an option

Save cixuuz/6d5f357e765fa8ea9e71154b62f4cc4d to your computer and use it in GitHub Desktop.
[125. Valid Palindrome] #leetcode
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