标签:
class Solution { public: int NumberOf1Between1AndN_Solution(int n) { if(n<=0) return 0; int count=0; int i=1; while(i<=n) { int p=i; while(p) { if(p%10==1) count++; p=p/10; } i++; } return count; } };
剑指offer32 整数中1出现的次数(从1到n整数中1出现的次数)
标签:
原文地址:http://www.cnblogs.com/summerkiki/p/5538421.html