Function to convert x into its digit vector and uses count ( ) function to return the required count
static int solve ( int x ) { Vector < Integer > num = new Vector < Integer > ( ) ; while ( x > 0 ) { num . add ( x % 10 ) ; x /= 10 ; } Collections . reverse ( num ) ;