贴一个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

相关推荐

安静的鲸鱼offer...:神仙级别hr,可遇不可求,甚至他可能也是突然有感而发。只能说遇上是件幸事。
秋招开始捡漏了吗
点赞 评论 收藏
分享
12-12 21:52
武汉大学 Java
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务