Skip to content

Commit 5afbe53

Browse files
authored
Merge pull request #1811 from DaleSeo/main
[DaleSeo] WEEK 03 solutions
2 parents 7b5a99e + 1dbaa71 commit 5afbe53

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

valid-palindrome/DaleSeo.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// TC: O(n)
2+
// SC: O(1)
3+
impl Solution {
4+
pub fn is_palindrome(s: String) -> bool {
5+
let bytes = s.as_bytes();
6+
let (mut low, mut high) = (0, bytes.len() - 1);
7+
while low < high {
8+
while low < high && !bytes[low].is_ascii_alphanumeric() {
9+
low += 1
10+
}
11+
while low < high && !bytes[high].is_ascii_alphanumeric() {
12+
high -= 1
13+
}
14+
if low == high {
15+
return true;
16+
}
17+
if bytes[low].to_ascii_lowercase() != bytes[high].to_ascii_lowercase() {
18+
return false;
19+
}
20+
low += 1;
21+
high -= 1;
22+
}
23+
true
24+
}
25+
}

0 commit comments

Comments
 (0)