LeetCode 第 231 題 (Power of Two)
LeetCode 第 231 題 (Power of Two)
Given an integer, write a function to determine if it is a power of two.
這個題目有個特別簡單的解法。當然,能夠獨自想出這個方法可不簡單。這種方法可以作為一個知識點記住就好了。
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n <= 0) return false;
return !(n & (n - 1));
}
};
相關文章
- Leetcode 231 Power of TwoLeetCode
- Leetcode 231. Power of TwoLeetCode
- 【LeetCode 231_整數_位運算】Power of TwoLeetCode
- Leetcode Power of TwoLeetCode
- LeetCode 第 342 題(Power of Four)LeetCode
- [LeetCode-231] Power of Two(判斷一個數是不是2的若干次冪)LeetCode
- LeetCode 第 326 題 (Power of Three)LeetCode
- LeetCode 第 21 題 (Merge Two Sorted Lists)LeetCode
- LeetCode #1:Two Sum(簡單題)LeetCode
- Leetcode Two SumLeetCode
- Leetcode 1 two sumLeetCode
- Leetcode-Two SumLeetCode
- Two Sum leetcode javaLeetCodeJava
- LeetCode | 1 Two SumLeetCode
- leetcode 231 2的冪LeetCode
- Leetcode第1~10題LeetCode
- LeetCode 解題報告 - 2. Add Two NumbersLeetCode
- LeetCode-two sum:python解答陣列問題LeetCodePython陣列
- [LeetCode]1.Two SumLeetCode
- LeetCode----1. Two SumLeetCode
- LeetCode 1.Two NumsLeetCode
- LeetCode1:Two SumLeetCode
- Leetcode Divide Two IntegersLeetCodeIDE
- Leetcode Add Two NumbersLeetCode
- [LeetCode]1. Two SumLeetCode
- LeetCode OJ : 1 Two SumLeetCode
- LeetCode-1 Two SumLeetCode
- LeetCode | 349 Intersection Of Two ArraysLeetCode
- LeetCode題解第122題LeetCode
- LeetCode刷題之第701題LeetCode
- LeetCode 第 69 題 (Sqrt(x))LeetCode
- LeetCode 第 7 題(Reverse Integer)LeetCode
- LeetCode 第 343 題 (Integer Break)LeetCode
- LeetCode 第 66 題 (Plus One)LeetCode
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- Leetcode 326. Power of ThreeLeetCode
- LeetCode 2 Add Two NumbersLeetCode
- LeetCode: Two sum(兩數之和)LeetCode