当前位置:网站首页>Leetcode 2048. 下一个更大的数值平衡数(有点意思,已解决)
Leetcode 2048. 下一个更大的数值平衡数(有点意思,已解决)
2022-06-09 10:24:00 【我不是萧海哇~~~~】

如果整数 x 满足:对于每个数位 d ,这个数位 恰好 在 x 中出现 d 次。那么整数 x 就是一个 数值平衡数 。
给你一个整数 n ,请你返回 严格大于 n 的 最小数值平衡数 。
示例 1:
输入:n = 1
输出:22
解释:
22 是一个数值平衡数,因为:
- 数字 2 出现 2 次
这也是严格大于 1 的最小数值平衡数。
示例 2:
输入:n = 1000
输出:1333
解释:
1333 是一个数值平衡数,因为:
- 数字 1 出现 1 次。
- 数字 3 出现 3 次。
这也是严格大于 1000 的最小数值平衡数。
注意,1022 不能作为本输入的答案,因为数字 0 的出现次数超过了 0 。
示例 3:
输入:n = 3000
输出:3133
解释:
3133 是一个数值平衡数,因为:
- 数字 1 出现 1 次。
- 数字 3 出现 3 次。
这也是严格大于 3000 的最小数值平衡数。
提示:
- 0 <= n <= 10^6
Code:
class Solution {
public:
int nextBeautifulNumber(int n) {
for(int i=n+1;i<=10000000;i++)
{
string str=to_string(i);
int cnt1= count(str.begin(),str.end(),'1');
int cnt2= count(str.begin(),str.end(),'2');
int cnt3= count(str.begin(),str.end(),'3');
int cnt4= count(str.begin(),str.end(),'4');
int cnt5= count(str.begin(),str.end(),'5');
int cnt6= count(str.begin(),str.end(),'6');
// 1000 1333
// 1111
if(cnt1!=1)
{
cnt1=0;
}
if(cnt2!=2)
{
cnt2=0;
}
if(cnt3!=3)
{
cnt3=0;
}
if(cnt4!=4)
{
cnt4=0;
}
if(cnt5!=5)
{
cnt5=0;
}
if(cnt6!=6)
{
cnt6=0;
}
if((cnt1+cnt2+cnt3+cnt4+cnt5+cnt6)==str.length())
{
return i;
}
}
return 0;
}
};
边栏推荐
- [pyhton practice] - batch [Dragon Boat Festival] poster Download
- Is it safe for CICC fortune to open an account
- Forty four - wechat applet canvas unlocking and spring physical effect animation
- Publication of the prize for contribution - Essay solicitation activity for lightweight application server (April)
- AI candidates scored 48 points in challenging the composition of the college entrance examination; IBM announced its withdrawal from the Russian market and has suspended all business in Russia; Opencv
- 全局组织结构控制之抢滩登陆
- 4.【素短语,最左素短语】
- Learning fuzzy from SQL injection to bypass the latest safe dog WAF
- Dotnet core can also coordinate distributed transactions!
- 【Pyhton 实战】---- 批量【端午节】海报下载
猜你喜欢

Daily question -1232 Dotted line

計網 | OSI模型中各層單比特

三拾壹- NodeJS簡單代理池(合) 之 MongoDB 鏈接數爆炸了

叶酸配体的金属有机骨架材料MOFs负载5-氟尿嘧啶,西达本胺,紫杉醇,阿霉素,柔红霉素等药物

Eight sorting methods (difficulty: heap sort merge sort quick sort)

Network planning | units of each layer in OSI model

Interaction between C language and Lua (practice 2)

Redis的使用

用80%的工时拿100%的薪水,英国正式开启“四天工作制”试验!

error NU1202: Package Volo.Abp.Cli 5.2.1 is not compatible with netcoreapp3.1
随机推荐
C语言与Lua的交互(实践二)
NFT market has entered the era of aggregation, and okaleido has become the first aggregation platform on BNB chain
MKS H3615NS 直流电机驱动 使用说明书
Is it safe to open an account at flush
web开发重点,简单开发web
每日一题-1200. 最小绝对差
Comptage du réseau | unités de chaque couche du Modèle OSI
MOFs, metal organic framework materials of folate ligands, are loaded with 5-fluorouracil, sidabelamine, taxol, doxorubicin, daunorubicin and other drugs
Harbor正确密码登录不上去
DM 平台管理 - netcore
error NU1202: Package Volo.Abp.Cli 5.2.1 is not compatible with netcoreapp3.1
【mysql进阶】利用执行计划explain优化sql(二)
啥是腾讯PBD ,看我给讲讲
After ten years of deep cultivation, Xuanwu cloud technology finally sits firmly at the leading position of FMCG SaaS
[机缘参悟-20]:鬼谷子-反应篇-动静之术、说听结合、沉默是金
merge sort
From "no one cares" to comprehensive competition, the first 10 years of domestic industrial control safety
Flitter generate Poster
Mof-53nps loaded antibacterial molecule vancomycin (MOF metal organic framework loaded protein polypeptide drugs)
MOS管从入门到精通