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