We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A solution in python using the bitwise XOR operator. Works because when the loop cycles through a number twice, that bit flips back to zero (effectively erasing it). At the end, it's a matter of seeing which bit is the last one standing and then converting it back to base 10 based on its position.
deflonelyinteger(a):# Write your code herebinary_list=0forelementina:binary_list=binary_list^(2**element)returnint(math.log(binary_list,2))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →
A solution in python using the bitwise XOR operator. Works because when the loop cycles through a number twice, that bit flips back to zero (effectively erasing it). At the end, it's a matter of seeing which bit is the last one standing and then converting it back to base 10 based on its position.