-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3032.cpp
52 lines (44 loc) · 1.04 KB
/
3032.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "leetcode.hpp"
class Solution {
public:
int numberCount(int a, int b) {
int sum = 0;
for (auto i = a; i <= b; ++i) {
int digits[10] = {0};
string s = to_string(i);
for (int j = 0; j < s.size(); ++j) {
if (digits[s[j] - '0'] != 0) {
sum++;
break;
} else {
digits[s[j] - '0'] = 1;
}
}
}
return b - a + 1 - sum;
}
};
int main(int argc, char const *argv[]) {
/**
Example 1:
Input: a = 1, b = 20
Output: 19
Explanation: All the numbers in the range [1, 20] have unique digits
except 11. Hence, the answer is 19.
Example 2:
Input: a = 9, b = 19
Output: 10
Explanation: All the numbers in the range [9, 19] have unique digits
except 11. Hence, the answer is 10.
Example 3:
Input: a = 80, b = 120
Output: 27
Explanation: There are 41 numbers in the range [80, 120], 27 of which have
unique digits.
**/
Solution s;
auto ret = s.numberCount(1, 20);
ret = s.numberCount(9, 19);
ret = s.numberCount(80, 120);
return 0;
}