We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ee7a3bc commit 203eed4Copy full SHA for 203eed4
rust/0680-valid-palindrome-II.rs
@@ -0,0 +1,33 @@
1
+impl Solution {
2
+ pub fn valid_palindrome(s: String) -> bool {
3
+ fn is_palindrome(s: &[u8]) -> Option<(usize, usize)> {
4
+ let (mut i, mut j) = (0, s.len() - 1);
5
+ while i < j {
6
+ if s[i] != s[j] {
7
+ return Some((i, j));
8
+ }
9
+ i += 1;
10
+ j -= 1;
11
12
+
13
+ None // is palindrome
14
15
16
+ let s = s.as_bytes().to_vec();
17
+ match is_palindrome(&s) {
18
+ Some((i, j)) => {
19
+ if is_palindrome(&s[i+1..=j]).is_none() {
20
+ return true;
21
22
+ if is_palindrome(&s[i..=j-1]).is_none() {
23
24
25
26
+ None => {
27
28
29
30
31
+ false
32
33
+}
0 commit comments