lc 231 Power of Two


231 Power of Two

Given an integer, write a function to determine if it is a power of two.

analysation##

Easy problem.

solution

bool isPowerOfTwo(int n) {
if (n <= 0)
return false;
while (n%2 == 0)
n = n>>1;
return (n == 1);
}

LN : leetcode 231 Power of Two的更多相关文章

  1. [LeetCode] 231 Power of Two && 326 Power of Three && 342 Power of Four

    这三道题目都是一个意思,就是判断一个数是否为2/3/4的幂,这几道题里面有通用的方法,也有各自的方法,我会分别讨论讨论. 原题地址:231 Power of Two:https://leetcode. ...

  2. [LeetCode] 231. Power of Two 2的次方数

    Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...

  3. LeetCode 231 Power of Two

    Problem: Given an integer, write a function to determine if it is a power of two. Summary: 判断一个数n是不是 ...

  4. Leetcode 231 Power of Two 数论

    同样是判断数是否是2的n次幂,同 Power of three class Solution { public: bool isPowerOfTwo(int n) { ) && ((( ...

  5. (easy)LeetCode 231.Power of Two

    Given an integer, write a function to determine if it is a power of two. Credits:Special thanks to @ ...

  6. Java [Leetcode 231]Power of Two

    题目描述: Given an integer, write a function to determine if it is a power of two. 解题思路: 判断方法主要依据2的N次幂的特 ...

  7. [LeetCode] 231. Power of Two ☆(是否2 的幂)

    描述 Given an integer, write a function to determine if it is a power of two. 给定一个整数,编写一个函数来判断它是否是 2 的 ...

  8. 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的 ...

  9. leetcode 231 Power of Two(位运算)

    Given an integer, write a function to determine if it is a power of two. 题解:一次一次除2来做的话,效率低.所以使用位运算的方 ...

随机推荐

  1. springboot+idea+maven学习第一天(springboot入门,idea整合maven)

    1.springboot简介 简化Spring 用用开发的一个框架: 真个S僻壤技术栈的一个大整合 j2ee开发的一站式解决方案 2.微服务 微服务:是一种架构风格 一个应用应该是一组小型服务:可以通 ...

  2. list去重精简代码版

    List<String> list = new ArrayList<>(); list.add("111"); list.add("111&quo ...

  3. MySQL使用教程收集(语法教程/命令教程)

    说明:现在市面上的教程除了基本语法外,都基本是五花八门的,最权威且最全面的解释应该上官网去查看. https://www.tutorialspoint.com/mysql/index.htm http ...

  4. 使用Post方法模拟登陆爬取网页(转)

    使用Post方法模拟登陆爬取网页   最近弄爬虫,遇到的一个问题就是如何使用post方法模拟登陆爬取网页.下面是极简版的代码: import java.io.BufferedReader; impor ...

  5. dstat用法;利用awk求dstat所有列每列的和;linux系统监控

    安装:yum install -y dstat dstat命令是一个用来替换vmstat.iostat.netstat.nfsstat和ifstat这些命令的工具,是一个全能系统信息统计工具.与sys ...

  6. git的配置文件

    转载:https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ Git Config ...

  7. Network problem solving flow chart

    来自为知笔记(Wiz)

  8. activiti自己定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义

    注:(1)环境搭建:activiti自己定义流程之Spring整合activiti-modeler5.16实例(一):环境搭建         (2)创建流程模型:activiti自己定义流程之Spr ...

  9. 两个月后才更新一篇。。。。LIB和DLL的差别

     共同拥有两种库: 一种是LIB包括了函数所在的DLL文件和文件里函数位置的信息(入口).代码由执行时载入在进程空间中的DLL提供,称为动态链接库dynamic link library. 一种是 ...

  10. kafka 生产者消费者 api接口

    生产者 import java.util.Properties; import kafka.javaapi.producer.Producer; import kafka.producer.Keyed ...