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; } };
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; } };
转载于:https://www.cnblogs.com/summerkiki/p/5538421.html