LeetCode 680. Valid Palindrome II #96
quinnwencn
started this conversation in
General
Replies: 1 comment
-
AnalysisSolution written in RustSolution written in Cppclass Solution {
public:
bool validPalindrome(string s) {
int left = 0;
int right = s.length() - 1;
while (left < right) {
if (s[left] != s[right]) {
return helper(s, left, right - 1) || helper(s, left + 1, right);
}
left++;
right--;
}
return true;
}
bool helper(const std::string& s, int left, int right) {
while (left < right) {
if (s[left] != s[right]) {
return false;
}
left++;
right--;
}
return true;
}
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Given a string s, return true if the s can be palindrome after deleting at most one character from it.
Example 1:
Input: s = "aba"
Output: true
Example 2:
Input: s = "abca"
Output: true
Explanation: You could delete the character 'c'.
Example 3:
Input: s = "abc"
Output: false
Constraints:
1 <= s.length <= 105
s consists of lowercase English letters.
Beta Was this translation helpful? Give feedback.
All reactions