From e13fc57ec16f6502c3a288d0e8b084c666aee07d Mon Sep 17 00:00:00 2001 From: Seinlin Date: Tue, 7 Feb 2023 23:17:51 -0800 Subject: [PATCH] Add c/0680-valid-palindrome-ii.c --- c/0680-valid-palindrome-ii.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 c/0680-valid-palindrome-ii.c diff --git a/c/0680-valid-palindrome-ii.c b/c/0680-valid-palindrome-ii.c new file mode 100644 index 000000000..283643782 --- /dev/null +++ b/c/0680-valid-palindrome-ii.c @@ -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; +}