-
Notifications
You must be signed in to change notification settings - Fork 0
/
647-palindromic-substrings.cpp
54 lines (44 loc) · 1.18 KB
/
647-palindromic-substrings.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
int countSubstrings(string s) {
int res = 0;
int l, r, m = 0;
int len = s.length();
for(l = 0; l < len; l++){
for(m = l; m < len; m++){
int is1 = 1;
int is2 = 1;
for(r = m; r <= m + m - l; r++){
if(r == len || s[r] != s[m - (r - m)]){
is1 = 0;
break;
}
}
if(is1 == 1){
res += 1;
cout << "s1: " << s.substr(l, (r - l)) << endl;
}
for(r = m + 1; r <= m + m - l + 1; r++){
if(r == len || s[r] != s[m - (r - m) + 1]){
is2 = 0;
break;
}
}
if(is2 == 1){
res += 1;
cout << "s2: " << s.substr(l, (r - l)) << endl;
}
}
}
return res;
}
};
int main(){
Solution sol;
string s ("");
sol.countSubstrings(s);
return 0;
}