Skip to content

Commit e13fc57

Browse files
committed
Add c/0680-valid-palindrome-ii.c
1 parent 0a937c5 commit e13fc57

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

c/0680-valid-palindrome-ii.c

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
bool validPalindromeLR(char * s, int left, int right){
2+
while (left < right) {
3+
if (s[left] != s[right]) {
4+
return false;
5+
}
6+
left++;
7+
right--;
8+
}
9+
10+
return true;
11+
}
12+
13+
bool validPalindrome(char * s){
14+
int left = 0;
15+
int right = strlen(s) - 1;
16+
17+
while (left < right) {
18+
if (s[left] != s[right]) {
19+
return validPalindromeLR(s, left + 1, right) || validPalindromeLR(s, left, right - 1);
20+
}
21+
left++;
22+
right--;
23+
}
24+
25+
return true;
26+
}

0 commit comments

Comments
 (0)