How to reduce the time complexity of this code.
The task is given two numbers to find all numbers in this range that have unique numbers. For example, in range 1 to 20, number 11 has two 1's so it's not considered unique. Another example number 1252 is not unique as 2 is repeated 2 times in this number.
Here is my code:
Input:
m = 10, n = 50
Program:
int count = 0;
for(int i=m; i<=n; i++) {
String str = String.valueOf(i);
Set<Character> set = new HashSet<Character>();
for(char c : str.toCharArray()) {
set.add(c);
}
if(set.length() == str.length()) {
count++;
}
}
print(count);