Skip to content

Commit e252fd1

Browse files
authored
Create 2048. Next Greater Numerically Balanced Number (#916)
2 parents b1db50b + 0bda146 commit e252fd1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
bool solve(int x){
4+
string s=to_string(x);
5+
vector<int> vec(10,0);
6+
for(auto i:s){
7+
vec[i-'0']++;
8+
}
9+
for(auto i:s){
10+
int c=i-'0';
11+
if(c==0 || vec[c]!=c){
12+
return 0;
13+
}
14+
}
15+
return 1;
16+
}
17+
int nextBeautifulNumber(int n) {
18+
for(int i=n+1; ;i++){
19+
if(solve(i)){
20+
return i;
21+
}
22+
}
23+
}
24+
};

0 commit comments

Comments
 (0)