Numbers having Unique ( or Distinct ) digits | C ++ code for the above approach ; Function to print unique numbers ; Iterate from l to r ; Convert the no . to string ; Convert string to set using stl ; Output if condition satisfies ; Driver Code ; Input of the lower and higher limits ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printUnique ( int l , int r ) { for ( int i = l ; i <= r ; i ++ ) { string s = to_string ( i ) ; set < int > uniDigits ( s . begin ( ) , s . end ( ) ) ; if ( s . size ( ) == uniDigits . size ( ) ) { cout << i << " ▁ " ; } } } int main ( ) { int l = 1 , r = 20 ; printUnique ( l , r ) ; return 0 ; }