码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-10-13 18:58:48      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:off   1出现的次数   java   +=   while   public   for   tween   剑指offer   

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;
    }
}

  

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

标签:off   1出现的次数   java   +=   while   public   for   tween   剑指offer   

原文地址:http://www.cnblogs.com/toov5/p/7662370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!