安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

Swift 判断一个数是否为2的幂

  • 日期: 2027-07-04
  • 标签: 常规

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.

Swift 判断一个数是否为2的幂

原文地址: https://www.cveoy.top/t/topic/pZtQ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: Minecraft 服务器官网 - 最棒的 [你的服务器名称] 体验
  • 下一篇: C++ 大数相加代码示例 - 处理任意长度数字

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2