Click here to see the full article post
return (n&3) is better , i think ...but why time is same? who can tell me , thank you!
@yake For example, the binary presentation of 4 is 100, 8 is 1000..., which means the last two bits is always 0 if the number is 4's multiples. So n & 3 (n & 11) is for checking if the number is 4's multiples, and that is the result, too.
How is it even possible for other solutions to take lesser time than my solution? Mine beats only 11.73% of the submissions?
I just did return(n&3). :'(
@yake: Compiler will probably optimize that anyway. In that case, I rather use the remainder which would be more clear.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.