Given an integer, write a function to determine if it is a power of two
生活随笔
收集整理的這篇文章主要介紹了
Given an integer, write a function to determine if it is a power of two
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Given an integer, write a function to determine if it is a power of two.
判斷一個整數(shù)是不是2的次方:
class Solution { public:bool isPowerOfTwo(int n) {int cnt = 0;while (n > 0) {cnt += (n & 1);n >>= 1;}return cnt == 1;} };
總結(jié)
以上是生活随笔為你收集整理的Given an integer, write a function to determine if it is a power of two的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kth Largest Element
- 下一篇: HOG特征向量的代码