-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path680.valid-palindrome-ii.cpp
More file actions
41 lines (41 loc) · 1.06 KB
/
680.valid-palindrome-ii.cpp
File metadata and controls
41 lines (41 loc) · 1.06 KB
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
38
39
40
41
class Solution {
public:
bool validPalindrome(string s) {
// int i=0, j=s.length()-1;
// int count=0;
// while(i<=j)
// {
// if(s[i] != s[j])
// {
// if(count == 1)
// return false;
// if(s[i] == s[j-1])
// {
// count++;
// j--;
// }
// else if(s[i+1] ==s[j])
// {
// i++;
// count++;
// }
// else
// return false;
// }
// i++;
// j--;
// }
// return true;
int n = s.size(), h = (n) / 2;
for (int i = 0; i < h; ++i) {
if (s[i] != s[n - 1 - i]) {
for (int j = i; j < h; ++j) {
if (s[j] != s[n - 1 -j -1] && s[j+1] != s[n - 1 - j])
return false;
}
return true;
}
}
return true;
}
};