作者归档:在线疯狂

RSS feed of 在线疯狂

[LeetCode]Number of 1 Bits

题目描述:

Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).

For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should return 3 ...

继续阅读

[LeetCode]Reverse Bits

题目描述:

Reverse bits of a given 32 bits unsigned integer.

For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).

Follow up:
If this function is called many times, how would you optimize ...

继续阅读

Python实现整数均分

将整数m划分为n个整数,使得到的整数之间的差值不超过1,结果按照升序排列。

例如输入55, 6,返回[9, 9, 9, 9, 9, 10]。

Python代码:

def splitInteger(m, n):
    assert n > 0
    quotient = m / n
    remainder = m % n
    if remainder > 0:
        return [quotient] * (n - remainder) + [quotient + 1] * remainder
    if remainder ...

继续阅读