If the current digit is 1 , any digit from [ 1 - 9 ] can be placed . If N == 1 , 0 can also be placed
if ( digit == 1 ) { for ( int i = ( N == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , N ) ; } }