Count of unique digits in a given number N | Java program for the above approach ; Function that returns the count of unique digits of number N ; Initialize a variable to store count of unique digits ; Initialize cnt array to store digit count ; Iterate through digits of N ; Retrieve the last digit of N ; Increase the count of the last digit ; Remove the last digit of N ; Iterate through the cnt array ; If frequency of digit is 1 ; Increment the count of unique digits ; Return the count of unique digit ; Driver Code ; Given Number N ; Function Call
import java . util . * ; class GFG { public static void countUniqueDigits ( int N ) { int res = 0 ; int cnt [ ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; while ( N > 0 ) { int rem = N % 10 ; cnt [ rem ] ++ ; N = N / 10 ; } for ( int i = 0 ; i < cnt . length ; i ++ ) { if ( cnt [ i ] == 1 ) { res ++ ; } } System . out . println ( res ) ; } public static void main ( String [ ] args ) { int N = 2234262 ; countUniqueDigits ( N ) ; } }