forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0902.cpp
More file actions
25 lines (23 loc) · 697 Bytes
/
0902.cpp
File metadata and controls
25 lines (23 loc) · 697 Bytes
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
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int atMostNGivenDigitSet(vector<string>& D, int N)
{
string N_s = to_string(N+1);
int n = N_s.size(), res = 0;
for (int i = 1; i < n; ++i)
{
res += pow(D.size(), i);
}
int i = 0;
unordered_set<string> Dset(D.begin(), D.end());
for (; i < n; ++i)
{
int tmp = count_if(D.begin(), D.end(), [&](const string d){return d[0] < N_s[i];});
res += tmp*pow(D.size(), n - i - 1);
if (!Dset.count(string(1, N_s[i]))) break;
}
return res;
}
};