摘要: public int[] CountBits(int n) { int[] res = new int[n + 1]; for (int i = 0; i <= n; i++) { res[i] = CountOnesWithBitOperation(i); } return res; } publ 阅读全文
posted @ 2025-11-14 14:55 honyide 阅读(4) 评论(0) 推荐(0)
摘要: public int CountOnesWithBitOperation(int n) { int count = 0; while (n != 0) { n &= (n - 1); // 消除最右边的1 count++; } return count; } 阅读全文
posted @ 2025-11-14 14:35 honyide 阅读(4) 评论(0) 推荐(0)