13
6
0
int cal(int a){ int res = 0; while(a){ if(a%10 == 1){ res++; } a /= 10; } return res; } int NumberOf1Between1AndN_Solution(int n ) { // write code here int res = 0; for(int i = 1; i <= n; i++){ res += cal(i); } return res; }
int NumberOf1Between1AndN_Solution(int n ) { // write code here if(n==0) return 0; int sum=0; for(int i=1;i<=n;i++){ int j,t=i; while(1) { if(j==1) sum++; j=t%10; t=t/10; if(t==0&&j==0) break; } } return sum; }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题