Advertisement
fooker

Kernighan's Algorithm

Nov 20th, 2022
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.16 KB | None | 0 0
  1. // kernighan's algorithm
  2. ll numberofones(ll n){
  3.     ll counter = 0;
  4.     while (n) {
  5.         n &= (n - 1);
  6.         counter++;
  7.     }
  8.     return counter;
  9. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement