Next Greater Numerically Balanced Number LeetCode solution in C++

1
class Solution {
2
public:
3
bool valid(int n) {
4
vector<int> map(10, 0);
5
while (n) {
6
int rem = n % 10;
7
map[rem]++;
8
n = n / 10;
9
}
10
for (int i = 0; i < 10; i++)
11
if (map[i] && map[i] != i) return false;
12
return true;
13
}
14

15
int nextBeautifulNumber(int n) {
16
while (true) {
17
++n;
18
if (valid(n)) return n;
19
}
20
return 1;
21
}
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0