|
@@ -0,0 +1,28 @@
|
|
|
+struct Solution;
|
|
|
+
|
|
|
+impl Solution {
|
|
|
+ pub fn is_palindrome(s: String) -> bool {
|
|
|
+ let forward = s.chars()
|
|
|
+ .filter (|c| c.is_alphanumeric())
|
|
|
+ .map(|c| c.to_lowercase().to_string());
|
|
|
+
|
|
|
+ let backward = s.chars()
|
|
|
+ .rev()
|
|
|
+ .filter (|c| c.is_alphanumeric())
|
|
|
+ .map(|c| c.to_lowercase().to_string());
|
|
|
+
|
|
|
+ forward.partial_cmp(backward)==Some(std::cmp::Ordering::Equal)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[cfg(test)]
|
|
|
+mod tests {
|
|
|
+ use super::*;
|
|
|
+
|
|
|
+ #[test]
|
|
|
+ fn test_ispalindrome() {
|
|
|
+ let s = String::from("A man, a plan, a canal: Panama");
|
|
|
+ let res = Solution::is_palindrome(s);
|
|
|
+ assert_eq!(res, true);
|
|
|
+ }
|
|
|
+}
|