贴一个C++版代码 class Solution { public: int NumberOf1Between1AndN_Solution(int n) { int base=1; int res=0; while(base<=n){ int cur=n/base%10; int a=n/base/10; int b=n%base; //分三种情况讨论 if(cur==1){ res+=a*base+b+1; }else if(cur==0){ res+=a*base; }else{ res+=(a+1)*base; } base*=10; } return res; } };
1

相关推荐

程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
仁者伍敌:难怪小公司那么挑剔,让你们这些大佬把位置拿了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务