-
Notifications
You must be signed in to change notification settings - Fork 0
/
680.hpp
44 lines (37 loc) · 841 Bytes
/
680.hpp
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
42
43
44
#ifndef LEETCODE_680_HPP
#define LEETCODE_680_HPP
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
class Solution {
public:
bool validPalindrome(string s) {
int l = 0, r = static_cast<int>(s.length() - 1);
while (l < r) {
if (s[l] != s[r])
return isPalindromic(s, l + 1, r) || isPalindromic(s, l, r - 1);
l++;
r--;
}
return true;
}
private:
bool isPalindromic(string &s, int l, int r) {
while (l < r) {
if (s[l] != s[r])
return false;
l++;
r--;
}
return true;
}
};
#endif //LEETCODE_680_HPP