Total numbers with no repeated digits in a range | C ++ implementation of brute force solution . ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int repeated_digit ( int n ) { unordered_set < int > s ; while ( n != 0 ) { int d = n % 10 ; if ( s . find ( d ) != s . end ( ) ) { return 0 ; } s . insert ( d ) ; n = n / 10 ; } return 1 ; } int calculate ( int L , int R ) { int answer = 0 ; for ( int i = L ; i < R + 1 ; ++ i ) { answer = answer + repeated_digit ( i ) ; } return answer ; } int main ( ) { int L = 1 , R = 100 ; cout << calculate ( L , R ) ; return 0 ; }