-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2048.cpp
More file actions
43 lines (40 loc) · 854 Bytes
/
2048.cpp
File metadata and controls
43 lines (40 loc) · 854 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
Solution() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool check(int n) {
map<int, int> m;
string s = to_string(n);
for (auto c : s) {
if (c == '0') {
return false;
}
m[c - '0']++;
}
for (auto i = 1; i <= 9; i++) {
if (m[i] >= 1 && m[i] != i) {
return false;
}
}
return true;
}
int nextBeautifulNumber(int n) {
for (int i = n + 1; i <= 1224444; i++) {
if (check(i)) {
return i;
}
}
return -1;
}
};
int main() {
Solution s;
int n = 780001;
cout << s.nextBeautifulNumber(n) << endl;
return 0;
}