Skip to content

Commit 9fe8711

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 2.20 MB (Top 87.5%)
1 parent 621170a commit 9fe8711

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 2.20 MB (Top 87.5%)
2+
3+
impl Solution {
4+
pub fn valid_palindrome(s: String) -> bool {
5+
is_valid_palindrome::<false>(s.as_bytes())
6+
}
7+
}
8+
9+
fn is_valid_palindrome<const SKIPPED: bool>(mut s: &[u8])->bool{
10+
loop {
11+
match s {
12+
[b, middle @ .., e] if b == e => s = middle,
13+
[_, .., _] if !SKIPPED => return is_valid_palindrome::<true>(&s[1..])
14+
|| is_valid_palindrome::<true>(s.split_last().unwrap().1),
15+
[_, .., _] if SKIPPED => return false,
16+
_ => return true,
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)