leetcodeOJ 231. Power of Two
2017-04-06 12:01
106 查看
Given an integer, write a function to determine if it is a power of two.
//思路:power of two 表示n的bit位上只有一位为1
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n <= 0)
return false;
return !(n&(n-1));
}
};
//思路:power of two 表示n的bit位上只有一位为1
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n <= 0)
return false;
return !(n&(n-1));
}
};
相关文章推荐
- LeetCodeOJ_201_Bitwise AND of Numbers Range
- LeetCodeOJ_228_Summary Ranges
- leetcodeOJ 39
- leetcodeOJ 342. Power of Four
- leetcodeOJ 442. Find All Duplicates in an Array
- LeetCodeOJ1 Two Sum
- LeetCodeOJ_231_Power of Two
- leetcodeOJ 59
- leetcodeOJ 148. Sort List
- leetcodeOJ 63. Unique Paths II
- LeetCodeOJ_200_Number of Islands
- LeetCodeOJ_217_Contains Duplicate
- leetcodeOj:66. Plus One
- leetcodeOJ 23. Merge k Sorted Lists
- leetcodeOJ 71. Simplify Path
- LeetCodeOJ_199_Binary Tree Right Side View
- LeetCodeOJ_223_Rectangle Area
- leetcodeOJ 6. ZigZag Conversion
- leetcodeOJ 53. Maximum Subarray
- leetcodeOJ 80. Remove Duplicates from Sorted Array II