Skip to content

Bit operation / Power of Two, bit operation solution #10

Description

@yesiah

分享一個非常酷炫的位運算解法

bool isPowerOfTwo(int n) {
    return n > 0 && (n & (n - 1)) == 0;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions