Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1773 from AP-Repositories/patch-44
Browse files Browse the repository at this point in the history
Create 0680-valid-palindrome-ii.cpp
  • Loading branch information
Ahmad-A0 authored Jan 1, 2023
2 parents 8466381 + eabe2cf commit 3f36947
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cpp/0680-valid-palindrome-ii.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
private:
bool validPalindromeUtil(string s, int i, int j) {
while(i < j)
if(s[i] == s[j]) {
i += 1;
j -= 1;
} else
return false;
return true;
}
public:
bool validPalindrome(string s) {
int i = 0, j = s.length() - 1;

while(i < j)
if(s[i] == s[j]) {
i += 1;
j -= 1;
} else
return validPalindromeUtil(s, i + 1, j) || validPalindromeUtil(s, i, j - 1);
return true;
}
};

0 comments on commit 3f36947

Please sign in to comment.