剑指offer之 整数中1出现的次数

public class Solution {
    public int NumberOf1Between1AndN_Solution(int n) {
        int count=0;
        for(int i=1;i<=n;i++){
            
            count+=core(i);
        }
      
        return count;
    }
    private int core(int n){
        int num=0;
        while(n!=0){
            if(n%10==1){
                num++;
            }
            n/=10;
        }
        return num;
    }
}

  

posted @ 2017-10-13 17:52  toov5  阅读(169)  评论(0编辑  收藏  举报