From 1dbaa71e42dfe4d996e695b99d24612c436a8854 Mon Sep 17 00:00:00 2001 From: Dale Seo Date: Sat, 9 Aug 2025 18:06:52 -0400 Subject: [PATCH] valid-palindrome --- valid-palindrome/DaleSeo.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 valid-palindrome/DaleSeo.rs diff --git a/valid-palindrome/DaleSeo.rs b/valid-palindrome/DaleSeo.rs new file mode 100644 index 000000000..478cf8ecf --- /dev/null +++ b/valid-palindrome/DaleSeo.rs @@ -0,0 +1,25 @@ +// TC: O(n) +// SC: O(1) +impl Solution { + pub fn is_palindrome(s: String) -> bool { + let bytes = s.as_bytes(); + let (mut low, mut high) = (0, bytes.len() - 1); + while low < high { + while low < high && !bytes[low].is_ascii_alphanumeric() { + low += 1 + } + while low < high && !bytes[high].is_ascii_alphanumeric() { + high -= 1 + } + if low == high { + return true; + } + if bytes[low].to_ascii_lowercase() != bytes[high].to_ascii_lowercase() { + return false; + } + low += 1; + high -= 1; + } + true + } +}