forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
37 lines (36 loc) · 999 Bytes
/
solution.cpp
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
36
37
class Solution {
public:
bool validPalindrome(string s) {
bool skipFlag = true;
bool result = true;
for(int cur1=0, cur2=s.size()-1; cur1 < cur2; cur1++,cur2--){
if(s[cur1] != s[cur2]){
if(skipFlag && s[cur1+1] == s[cur2]){
cur1 ++;
skipFlag = false;
}
else{
result = false;
break;
}
}
}
if(result)
return result;
skipFlag = true;
result = true;
for(int cur1=0, cur2=s.size()-1; cur1 < cur2; cur1++,cur2--){
if(s[cur1] != s[cur2]){
if(skipFlag && s[cur1] == s[cur2-1]){
cur2 --;
skipFlag = false;
}
else{
result = false;
break;
}
}
}
return result;
}
};