| 1 | // hash set |
| 2 | class Solution { |
| 3 | public int countPalindromicSubsequence(String s) { |
| 4 | // find unique chars |
| 5 | HashSet<Character> set = new HashSet<>(); |
| 6 | int n = s.length(); |
| 7 | for(int i=0;i<n;i++){ |
| 8 | set.add(s.charAt(i)); //a,b,c |
| 9 | } |
| 10 | |
| 11 | int count=0; |
| 12 | for(char ch : set){ |
| 13 | int first=-1; |
| 14 | int last = -1; |
| 15 | for(int i=0;i<n;i++){ |
| 16 | if(ch == s.charAt(i)){ |
| 17 | if(first == -1){ |
| 18 | first = i; |
| 19 | } |
| 20 | last = i; |
| 21 | } |
| 22 | } |
| 23 | if(first == last) continue; |
| 24 | HashSet<Character> set1 = new HashSet<>(); |
| 25 | for(int i=first+1;i<last;i++){ |
| 26 | set1.add(s.charAt(i)); |
| 27 | } |
| 28 | count += set1.size(); |
| 29 | } |
| 30 | return count; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // map |
| 35 | class Solution { |
nothing calls this directly
no outgoing calls
no test coverage detected