We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 7b5a99e + 1dbaa71 commit 5afbe53Copy full SHA for 5afbe53
valid-palindrome/DaleSeo.rs
@@ -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