LeetCode-231
Links:https://leetcode.com/problems/power-of-two/
Given an integer, write a function to determine if it is a power of two.
思路:和前一篇一样。采用第一种方法。
http://blog.tk-xiong.com/archives/346
1 2 3 4 5 6 |
class Solution { public: bool isPowerOfTwo(int n) { return n>0 && (1<<31)%n==0?true:false; } }; |
【LeetCode】231. Power of Two