You are viewing a single comment's thread. Return to all comments →
More at https://github.com/pakbungdesu/hackerrank-problem-solving.git
Java
public static long sumXor(long n) { if (n == 0) { return 1; } else { String bin = Long.toBinaryString(n); int zero_bits = bin.length() - bin.replace("0", "").length(); return (long)Math.pow(2, zero_bits); } }
Pyhon
def sumXor(n): if n == 0: return 1 else: zero_bits = bin(n)[2:].count('0') # Ignore the '0b' prefix return 2**zero_bits
Seems like cookies are disabled on this browser, please enable them to open this website
Sum vs XOR
You are viewing a single comment's thread. Return to all comments →
More at https://github.com/pakbungdesu/hackerrank-problem-solving.git
Java
Pyhon