Skip to content

Commit

Permalink
Create 1930. Unique Length-3 Palindromic Subsequences1 (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Jan 4, 2025
2 parents 5c3ce42 + 11b7190 commit 7f72963
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 1930. Unique Length-3 Palindromic Subsequences1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Solution {
public:
int countPalindromicSubsequence(string s) {
vector<string>subbstr;
vector<int>a(26, 0);
int n = s.size();
for(int i = 0; i < n; i++){
if(a[s[i] - 'a'] == 0){
string sub = s.substr(i, n - i);
subbstr.push_back(sub);
a[s[i] - 'a'] = 1;
}
}
int res = 0;
for(int i = 0; i < subbstr.size(); i++){
a.clear();
a.resize(26, 0);
int j = subbstr[i].size() - 1;
while(j > 0 && subbstr[i][j] != subbstr[i][0]){
j--;
}
j -= 1;
while(j > 0 ){
if(a[subbstr[i][j] - 'a'] == 0){
res++;
a[subbstr[i][j] - 'a'] = 1;
}
j--;
}
}
return res;
}
};

0 comments on commit 7f72963

Please sign in to comment.