blob: 21d150f7206ff0028023e89dc945c17d13eba261 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <string>
using std::string;
bool strict_palindrome(string::const_iterator left, string::const_iterator right)
{
while (left < right)
{
if (*left != *right)
return false;
++left;
--right;
}
return true;
}
class Solution
{
public:
bool validPalindrome(string s)
{
string::const_iterator left = s.cbegin();
string::const_iterator right = s.cend() - 1;
while (left < right)
{
if (*left != *right)
return strict_palindrome(left, right - 1) || strict_palindrome(left + 1, right);
++left;
--right;
}
return true;
}
};
|