-
Notifications
You must be signed in to change notification settings - Fork 0
680_ValidPalindromeII
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
bool isPalindrome(string s, int l, int r){
while(l<r){
if(s[l++]!=s[r--]) return false;
}
return true;
}
bool validPalindrome(string s) {
int l=0, r=s.size()-1;
while(l<r){
if(s[l]!=s[r]) return isPalindrome(s, l+1,r) || isPalindrome(s, l,r-1);
l++;
r--;
}
return true;
}
};
- time complexity
O(n)
- space complexity
O(1)
footer