Integers from the range that are composed of a single distinct digit | Boolean function to check distinct digits of a number ; Take last digit ; Check if all other digits are same as last digit ; Remove last digit ; Function to return the count of integers that are composed of a single distinct digit only ; If i has single distinct digit ; Driver code
function checkDistinct ( x ) { var last = x % 10 ; while ( x > 0 ) { if ( x % 10 != last ) return false ; x = parseInt ( x / 10 ) ; } return true ; } function findCount ( L , R ) { var count = 0 ; for ( i = L ; i <= R ; i ++ ) { if ( checkDistinct ( i ) ) count += 1 ; } return count ; } var L = 10 , R = 50 ; document . write ( findCount ( L , R ) ) ;