Question
Requirement: O(1) time
Solution
Do a special handle for input = 0. source
bool IsPowerOfTwo(ulong x) {
return (x & (x - 1)) == 0;
}
Requirement: O(1) time
Do a special handle for input = 0. source
bool IsPowerOfTwo(ulong x) {
return (x & (x - 1)) == 0;
}
Author:
Permalink: https://mar2ndx.github.io/2014/07/04/pre-2017-2014-07-04-Check-Power-of-2/
License: Copyright (c) 2019 CC-BY-NC-4.0 LICENSE
Slogan: Do you believe in DESTINY?