1.eamples

Input:
Output:
Explanation: The binary representation of is (no leading zero bits), and its complement is . So you need to output .
Input:
Output:
Explanation: The binary representation of is (no leading zero bits), and its complement is . So you need to output .
Subscribe to see which companies asked this question.

2.solve

class Solution {
public:
int findComplement(int num) {
int mask=;
int temp = num;
while(num)
{
num>>=;
mask<<=;
}
mask--;
return (temp^mask);
}
};

  

小练习:补数 (Number Complement)的更多相关文章

  1. [Swift]LeetCode476. 数字的补数 | Number Complement

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

  2. 【LeetCode】476. 数字的补数 Number Complement

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:Leetcode, 力扣,476, 补数,二进制,Pyth ...

  3. 【leetcode】476. Number Complement

    problem 476. Number Complement solution1: class Solution { public: int findComplement(int num) { //正 ...

  4. LeetCode——Number Complement

    LeetCode--Number Complement Question Given a positive integer, output its complement number. The com ...

  5. LeetCode_Easy_471:Number Complement

    LeetCode_Easy_471:Number Complement 题目描述 Given a positive integer, output its complement number. The ...

  6. LeetCode_476. Number Complement

    476. Number Complement Easy Given a positive integer, output its complement number. The complement s ...

  7. LeetCode#476 Number Complement - in Swift

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

  8. LeetCode 476. Number Complement (数的补数)

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

  9. [LeetCode] Number Complement 补数

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

随机推荐

  1. ZOJ - 3229 Shoot the Bullet (有源汇点上下界最大流)

    题意:要在n天里给m个女生拍照,每个女生有拍照数量的下限Gi,每天有拍照数量的上限Di,每天当中每个人有拍照的上限Lij和Rij.求在满足限制的基础上,所有人最大能拍多少张照片. 分析:抛开限制,显然 ...

  2. JS的魅力

    一.初探JavaScript魅力 基本知识: JavaScript是什么 网页特效原理 -JavaScript就是修改样式 编写JS流程 - 布局:HTML + CSS - 属性:确定修改哪些属性 - ...

  3. Linux学习笔记之Linux启动引导过程

    早期时,启动一台计算机意味着要给计算机喂一条包含引导程序的纸带,或者手工使用前端面板地址/数据/控制开关来加载引导程序.尽管目前的计算机已经装备了很多工具来简化引导过程,但是这一切并没有对整个过程进行 ...

  4. 20145309《Java程序设计》第八周学习总结

    日志 •java.util.logging包提供了日志功能相关类与接口,使用日志的起点是logger类,Logger类的构造函数标示为protected,不是java.util.logging同包的类 ...

  5. bat(续六)-windows批处理set命令

    windows批处理set命令 [设置变量]格式:set 变量名=变量值详细:被设定的变量以%变量名%引用 [取消变量]格式:set 变量名=详细:取消后的变量若被引用%变量名%将为空 [展示变量]格 ...

  6. 一键安装 zabbix 2.0 版本 脚本

    原文地址: http://blog.csdn.net/u012449196/article/details/53859068 本文修改了原文中的部分错误,此脚本适用于zabbix 2.0 版本,以版本 ...

  7. C#实现日历样式的下拉式计算器

    C#实现日历样式的下拉式计算器 原文地址:http://developer.51cto.com/art/201508/487486.htm 如果我们正在做一个类似于库存控制和计费系统的项目,有些部分可 ...

  8. 通过visual studio修改dll或exe的版本信息

    可以编辑修改了 来自为知笔记(Wiz)

  9. [Pytorch]PyTorch使用tensorboardX(转

    文章来源: https://zhuanlan.zhihu.com/p/35675109 https://www.aiuai.cn/aifarm646.html 之前用pytorch是手动记录数据做图, ...

  10. Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException

    这个版本默认是开启了保护模式,进入redis的文件夹下的src 输入(前提是得开启redis服务): ./redis-cli config set protected-mode "no&qu ...