Put all obtained palindromes in a hash map to find only distinct palindromess
m . put ( s . substring ( 0 , 1 ) , 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j <= 1 ; j ++ ) for ( int rp = R [ j ] [ i ] ; rp > 0 ; rp -- ) m . put ( s . substring ( i - rp - 1 , i - rp - 1 + 2 * rp + j ) , 1 ) ; m . put ( s . substring ( i , i + 1 ) , 1 ) ; }