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
< ? php function checkDistinct ( $ x ) { $ last = $ x % 10 ; while ( $ x ) { if ( $ x % 10 != $ last ) return false ; $ x = floor ( $ x / 10 ) ; } return true ; } function findCount ( $ L , $ R ) { $ count = 0 ; for ( $ i = $ L ; $ i <= $ R ; $ i ++ ) { if ( checkDistinct ( $ i ) ) $ count += 1 ; } return $ count ; } $ L = 10 ; $ R = 50 ; echo findCount ( $ L , $ R ) ; ? >