Count unique numbers that can be generated from N by adding one and removing trailing zeros | C # implementation of the approach ; Function to count the unique numbers ; If the number has already been visited ; Insert the number to the set ; First step ; Second step remove trailing zeros ; Recur again for the new number ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void count_unique ( HashSet < int > s , int n ) { if ( s . Contains ( n ) ) return ; s . Add ( n ) ; n += 1 ; while ( n % 10 == 0 ) { n = n / 10 ; } count_unique ( s , n ) ; } public static void Main ( String [ ] args ) { int n = 10 ; HashSet < int > s = new HashSet < int > ( ) ; count_unique ( s , n ) ; Console . WriteLine ( s . Count ) ; } }