Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public int findComplement(int num) { int i=0, ans=1; do{ i++; ans*=2; }while((int)Math.pow(2,i) <= num && i<31); return (ans-1-num); }

Dang, that's a pretty elegant solution. That code in python looks like this:

def findComplement(num): """ :type num: int :rtype: int """ i=0 ans=1; while 2**i <= num: i +=1 ans *= 2 return (ans-1-num)

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