declare the map for store each char with occurrence
Dictionary < char , int > mp = new Dictionary < char , int > ( ) ; for ( i = 0 ; i < str . Length ; i ++ ) if ( mp . ContainsKey ( str [ i ] ) ) mp [ str [ i ] ] = mp [ str [ i ] ] + 1 ; else mp . Add ( str [ i ] , 1 ) ;