231 Power of Two 2的幂
给定一个整数,写一个函数来判断它是否是2的幂。
详见:https://leetcode.com/problems/power-of-two/description/
Java实现:
class Solution {public boolean isPowerOfTwo(int n) {return (n>0)&&((n&(n-1))==0);}
}
C++实现:
class Solution {
public:bool isPowerOfTwo(int n) {return (n>0)&&(!(n&(n-1)));}
};
转载于:https://www.cnblogs.com/xidian2014/p/8758944.html
231 Power of Two 2的幂相关推荐
- leetcode 231. Power of Two 判断是否为2的幂 Java
231. Power of Two Given an integer, write a function to determine if it is a power of two. Credits: ...
- LeetCode - 231. Power of Two - 判断一个数是否2的n次幂 - 位运算应用实例 - ( C++ )
1.题目:原题链接 Given an integer, write a function to determine if it is a power of two. 给定一个整数,判断该整数是否是2的 ...
- LeetCode - 231. Power of Two
Given an integer, write a function to determine if it is a power of two. Example 1: Input: 16 Output ...
- Leet Code OJ 231. Power of Two [Difficulty: Easy]
题目: Given an integer, write a function to determine if it is a power of two. 分析: 题意是给定一个整数,判断它是不是2的幂 ...
- leetcode python3 简单题231. Power of Two
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百三十一题 (1)题目 英文: Given an integer, write ...
- LeetCode 231: Power of Two
Given an integer, write a function to determine if it is a power of two. 判断一个数是否是2的幂,判断方法主要依据2的N次幂的特 ...
- leetcode 231. Power of Two
Given an integer, write a function to determine if it is a power of two. class Solution(object):def ...
- UVA 11149.Power of Matrix-矩阵快速幂倍增
Power of Matrix UVA - 11149 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include < ...
- 【LeetCode】231. Power of Two
题目: Given an integer, write a function to determine if it is a power of two. 非常简单的一道题目 class Solutio ...
最新文章
- 巨杉数据库完成数千万美元C轮融资,嘉实投资领投
- oracle11g注册在哪里,oracle 如何新建账号密码在suse11,oracle11g和tomcat开机自启动...
- 使用 Navicat Lite 连接 Oracle 数据库
- 微信生态中,「电商」如何借“运营工具”,抢占 4.5 亿流量红利?
- 敏捷软件开发学习笔记(四)之结构型设计模式
- Dart 13-Day
- 计算机多媒体发展2018,2018秋季学期计算机多媒体项目圆满结课
- DEFINE_MUTEX
- c语言编写面条排序算法,腾讯PCG事业部腾讯视频面经
- 廊坊市博实计算机网络工程有限公司,IP网络终端功放T-7760(含数字IP网络平台终端嵌入软件)...
- 符号集合近似法SAX
- js的柯里化(curry)
- GTA5最新线上小助手
- 数据中心的铜缆布线活力无限不过时
- sql compact 转mysql_如何将数据导入到 SQL Server Compact Edition 数据库中(四)
- E2UART编程(β板实操)task1传输helloworld
- 用Excel曲面图做等高线图(仿罗兰贝格消费者价值体系图)
- 2022年3月 python一级 程序题 【买本子和画三角形】
- CSS选择器(nth-child)
- 钉钉群机器人开发接口