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. WLAN QOS

    1. 理解WLAN QOS 1.1       WLAN QOS简介 802.11的WLAN网络为用户提供了公平竞争无线资源的无线接入服务,但不同的应用需求对于网络的要求是不同的,而原始802.11网 ...

  2. Spring-1-H Number Sequence(HDU 5014)解题报告及测试数据

    Number Sequence Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Pro ...

  3. saltstack常用模块

    介绍一些常用的saltstack模块,更多模块参考官方网站 1.跟安装包相关的模块:salt.states.pkg salt.states.pkg.downloaded(name, version=N ...

  4. excel日期插件

    效果图 Private Sub DTPicker1_Click() ActiveCell.Value = DTPicker1.Value DTPicker1.Visible = False End S ...

  5. Ubuntu 使用root登陆界面

    打开终端开启root账户 :sudo passwd -u root 输入当前用户的密码 2.为root账户设置密码:sudo passwd root 设置root密码,输入两次 3.进入到/usr/s ...

  6. ElasticSearch集群故障案例分析: 警惕通配符查询

    最近ElasticSearch集群出现了 https://elasticsearch.cn/article/171 文章中描述的情况,现在转载全文警示下自己. 许多有RDBMS/SQL背景的开发者,在 ...

  7. UVa 10883 超级平均数(二项式系数+对数计算)

    https://vjudge.net/problem/UVA-10883 题意: 给出n个数,每相邻两个数求平均数,依次类推,最后得到1个数,求该数. 思路: 演算一下可以发现最后各个数的系数就是二项 ...

  8. Python基础笔记系列十:模块

    本系列教程供个人学习笔记使用,如果您要浏览可能需要其它编程语言基础(如C语言),why?因为我写得烂啊,只有我自己看得懂!! 模块 #1.类比于java中的jar包,模块能让你能够有逻辑地组织你的Py ...

  9. 解压.zip,.tar.gz文件到指定目录,重命名文件

    1.解压文件到指定目录 /** * 解压文件到指定目录 * zipFile:要解压的文件 * descDir:解压到哪个文件 * */ @SuppressWarnings("rawtypes ...

  10. [postgreSql]postgreSql数据库、模式、表、函数的删除与创建

    1.删除/新增数据库    DROP DATABASE "testDB";    CREATE DATABASE "testDB" WITH OWNER = t ...