Skip to content

Small improvement to the power of 2 loop #314

@manishjain85

Description

@manishjain85

while((num & (num-1)) > 0){

This code can be improved by following the FenwayTree logic -

while ( num & (num-1) > 0) { 
   num = num + (num & -num)
}
return num

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