Mbpp/224

✅ 完美通过 Base: PASS Plus: PASS
测试评估
指标结果
Base 测试PASS
Plus 测试PASS
代码长度592 字符
模型生成的代码 (592 字符)
def count_Set_Bits(n: int) -> int:
    """
    Count the number of set bits (1s) in the binary representation of a non-negative integer.
    Uses Brian Kernighan's algorithm: repeatedly clears the lowest set bit.
    """
    # Handle negative numbers if needed; but problem likely expects non-negative.
    # We'll treat n as unsigned if negative? Typically for set bits it's non-negative.
    # To be safe, we can take abs or use bit length. Here we assume non-negative.
    count = 0
    while n:
        n &= n - 1  # clear the least significant bit set
        count += 1
    return count
Base 失败测试用例
  • 无失败测试
Plus 失败测试用例
  • 无失败测试