One Liner NON-RECURSIVE - Can you write an even shorter one?


  • 4
    F
    int getSum(int a, int b) {while (b=(~(a^=b)&b)<<1); return a;}

  • 0

    Very nice how you combined the two assignments! You could of course remove the spaces, and *2 could replace <<1. And does it have to be non-recursive?


  • 0
    F

    It doesn't have to be non-recursive, but top voted one is already a very short recursive version. So I'm not going to challenge that one.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.