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

leetcode338

时间:2017-04-30 01:11:09      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:tps   count   esc   href   class   ==   log   span   int   

public class Solution {
    public int[] CountBits(int num) {
        var ary = new int[num + 1];

            for (int i = 0; i <= num; i++)
            {
                var count = 0;
                var cur = i;
                do
                {
                    var c = cur % 2;
                    if (c == 1)
                    {
                        count++;
                    }
                    cur = cur / 2;
                } while (cur != 0);

                ary[i] = count;
            }

            return ary;
    }
}

https://leetcode.com/problems/counting-bits/#/description

leetcode338

标签:tps   count   esc   href   class   ==   log   span   int   

原文地址:http://www.cnblogs.com/asenyang/p/6786561.html

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