We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5c3ce42 + 11b7190 commit 7f72963Copy full SHA for 7f72963
1930. Unique Length-3 Palindromic Subsequences1
@@ -0,0 +1,33 @@
1
+class Solution {
2
+public:
3
+ int countPalindromicSubsequence(string s) {
4
+ vector<string>subbstr;
5
+ vector<int>a(26, 0);
6
+ int n = s.size();
7
+ for(int i = 0; i < n; i++){
8
+ if(a[s[i] - 'a'] == 0){
9
+ string sub = s.substr(i, n - i);
10
+ subbstr.push_back(sub);
11
+ a[s[i] - 'a'] = 1;
12
+ }
13
14
+ int res = 0;
15
+ for(int i = 0; i < subbstr.size(); i++){
16
+ a.clear();
17
+ a.resize(26, 0);
18
+ int j = subbstr[i].size() - 1;
19
+ while(j > 0 && subbstr[i][j] != subbstr[i][0]){
20
+ j--;
21
22
+ j -= 1;
23
+ while(j > 0 ){
24
+ if(a[subbstr[i][j] - 'a'] == 0){
25
+ res++;
26
+ a[subbstr[i][j] - 'a'] = 1;
27
28
29
30
31
+ return res;
32
33
+};
0 commit comments