Swift 判断一个数是否为2的幂
class Solution {\n func isPowerOfTwo(_ n: Int) -> Bool {\n return log2(Double(n)) == floor(log2(Double(n)))\n }\n}\n// The solution above checks if the logarithm of n to the base 2 is an integer or not. If it is an integer, then n is a power of 2.
原文地址: https://www.cveoy.top/t/topic/pZtQ 著作权归作者所有。请勿转载和采集!