Skip to content

Commit

Permalink
Add c/0680-valid-palindrome-ii.c
Browse files Browse the repository at this point in the history
  • Loading branch information
seinlin committed Feb 8, 2023
1 parent 0a937c5 commit e13fc57
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions c/0680-valid-palindrome-ii.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
bool validPalindromeLR(char * s, int left, int right){
while (left < right) {
if (s[left] != s[right]) {
return false;
}
left++;
right--;
}

return true;
}

bool validPalindrome(char * s){
int left = 0;
int right = strlen(s) - 1;

while (left < right) {
if (s[left] != s[right]) {
return validPalindromeLR(s, left + 1, right) || validPalindromeLR(s, left, right - 1);
}
left++;
right--;
}

return true;
}

0 comments on commit e13fc57

Please sign in to comment.