leetcode338

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode338相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode_338_CountingBits

leetcode338

leetCode 338

LeetCode338. Counting Bits (2 solutions)

[leetcode-338-Counting Bits]

leetcode 338