查了一下Integer.bitCount()的实现,肯定是记不住的啊ㄟ(▔▽▔)ㄏ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public int[] countBits(int num) { | |
int[] result = new int[num + 1]; | |
for (int i = 0; i <= num; i++) { | |
result[i] = Integer.bitCount(i); | |
} | |
return result; | |
} | |
} |
没有评论:
发表评论