A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return true if it is a palindrome, or false otherwise.
"amanaplanacanalpanama" is a palindrome.
"raceacar" is not a palindrome.
s is an empty string "" after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.
1 <= s.length <= 2 * 10^5s consists only of printable ASCII characters.No developer has claimed the Ruby throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
valid_s == valid_s.reverse to check whether it is a palindrome.# @param {String} s
# @return {Boolean}
def is_palindrome(s)
valid_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
valid_s = ''
s.downcase.chars.each do |char|
if valid_chars.include?(char)
valid_s << char
end
end
valid_s == valid_s.reverse
end
No developer has claimed the Python throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
valid_s == valid_s.reverse to check whether it is a palindrome.class Solution:
def isPalindrome(self, s: str) -> bool:
valid_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
valid_s = ''
for char in s.lower():
if char in valid_chars:
valid_s += char
return valid_s == valid_s[::-1]
No developer has claimed the Java throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
valid_s == valid_s.reverse to check whether it is a palindrome.class Solution {
public boolean isPalindrome(String s) {
var validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var validS = new StringBuilder();
for (char c : s.toLowerCase().toCharArray()) {
if (validChars.indexOf(c) != -1) {
validS.append(c);
}
}
var cleaned = validS.toString();
var reversed = validS.reverse().toString();
return cleaned.equals(reversed);
}
}
No developer has claimed the C++ throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Javascript throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Go throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Rust throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the C# throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Swift throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.
No developer has claimed the Kotlin throne for LeetCode #125 yet. Submit an optimal idiomatic solution to become the reigning king and display your portfolio dofollow backlink to visiting engineers worldwide.