Yuan Liu's Blog
Sunday, August 30, 2015
Leetcode 231. Power of Two
https://leetcode.com/problems/power-of-two/
2 one line solutions.
Solution 1:
return bin(n)[2:].count('1') == 1 and n > 0
Run time 64 ms;
Solution 2:
return n > 0 and (n & (n - 1)) == 0
Run time: 60 ms.
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment