Total numbers with no repeated digits in a range | Function to check if the given number has repeated digit or not ; Traversing through each digit ; if the digit is present more than once in the number ; return 0 if the number has repeated digit ; return 1 if the number has no repeated digit ; Function to find total number in the given range which has no repeated digit ; Traversing through the range ; Add 1 to the answer if i has no repeated digit else 0 ; Driver Code ; Calling the calculate
< ? php function repeated_digit ( $ n ) { $ c = 10 ; $ a = array_fill ( 0 , $ c , 0 ) ; while ( $ n > 0 ) { $ d = $ n % 10 ; if ( $ a [ $ d ] > 0 ) { return 0 ; } $ a [ $ d ] ++ ; $ n = ( int ) ( $ n / 10 ) ; } return 1 ; } function calculate ( $ L , $ R ) { $ answer = 0 ; for ( $ i = $ L ; $ i <= $ R ; $ i ++ ) { $ answer += repeated_digit ( $ i ) ; } return $ answer ; } $ L = 1 ; $ R = 100 ; echo calculate ( $ L , $ R ) ; ? >