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 #1:Two Sum(簡單題)LeetCode
- leetcode 231 2的冪LeetCode
- Leetcode 1 two sumLeetCode
- LeetCode | 1 Two SumLeetCode
- LeetCode題解第122題LeetCode
- Leetcode第1~10題LeetCode
- Leetcode 29 Divide Two IntegersLeetCodeIDE
- LeetCode 2 Add Two NumbersLeetCode
- LeetCode-1 Two SumLeetCode
- [LeetCode]1.Two SumLeetCode
- LeetCode | 349 Intersection Of Two ArraysLeetCode
- python: leetcode - 1 Two SumPythonLeetCode
- LeetCode刷題之第701題LeetCode
- 【CS231n】Spring 2020 Assignments - Assignment1 - Two Layer NetSpring
- leetcode231 2的冪(JAVA版)LeetCodeJava
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- leetcode-29. Divide Two IntegersLeetCodeIDE
- LeetCode-2 Add Two NumbersLeetCode
- Leetcode 21 Merge Two Sorted ListsLeetCode
- LeetCode: Two sum(兩數之和)LeetCode
- [LeetCode] 29. Divide Two IntegersLeetCodeIDE
- Leetcode 4 Median of Two Sorted ArraysLeetCode
- LeetCode 2. Add Two NumbersLeetCode
- 【Leetcode】1029. Two City SchedulingLeetCode
- leetcode 371. Sum of Two IntegersLeetCode
- LeetCode 21. Merge Two Sorted ListsLeetCode
- LeetCode 4. Median of Two Sorted ArraysLeetCode
- LeetCode Two Sum(001)解法總結LeetCode
- leetcode 350. Intersection of Two Arrays IILeetCode
- 【LeetCode】617. Merge Two Binary TreesLeetCode
- Leetcode 160. Intersection of Two Linked ListsLeetCode
- LeetCode 617. Merge Two Binary TreesLeetCode
- LeetCode T29 Divide Two IntegersLeetCodeIDE
- [leetcode 第 400 場周賽]題解LeetCode
- KMP演算法(Leetcode第28題)KMP演算法LeetCode
- leetcode的第9題:迴文數LeetCode
- python leetcode 之兩數之和(two sum)PythonLeetCode