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. MySql—模糊查询

    实例: SQL模糊查询,使用like比较关键字,加上SQL里的通配符,请参考以下:  1.LIKE 'Mc%' 将搜索以字母 Mc 开头的所有字符串(如 McBadden).  2.LIKE '%in ...

  2. Linux Java环境搭建

    -------------------------网络配置-------------------------------1.配置DNS:vi /etc/resolv.confnameserver 19 ...

  3. SQL学习笔记之MySQL索引知识点

    0x00 概述 之前写过一篇Mysql B+树学习,简单的介绍了B+数以及MySql使用B+树的原因, 有了这些基础知识点,对MySql索引的类型以及索引使用的一些技巧,就比较容易理解了. 0x01 ...

  4. JS类、对象、方法、prototype、_proto_

    案例代码: function People(name) { //对象属性 this.name = name; //对象方法 this.Introduce = function() { alert(&q ...

  5. Heartbeats

    很少有人否定,这是一首天籁.凄美动听的声音,触动的,是真正的灵魂深处.所谓“仁者见仁智者见智”,但有些东西是共通的,比如,我们的内心会被同一样东西触动.在这首动听的歌曲中,体现出那男女之间平凡又伟大的 ...

  6. Win7下硬盘安装fedora17

    Win7下硬盘安装fedora17 这几天经过很多次的百度和实验,终于成功的在我的x64机子上装上了fedora17,以此分享给大家,希望能给大家帮助. 一.准备工作: 1.工具,因为我们电脑上大部分 ...

  7. [JavaScript]YYYY-MM-DD格式字符串计算年龄

    function getAge(birth){ birth = birth.replace(/-/g,"/"); //把格式中的"-"替换为"/&qu ...

  8. 【bzoj2734】集合选数(有点思维的状压dp)

    题目传送门:bzoj2734 这题一个月前看的时候没什么头绪.现在一看,其实超简单. 我们对于每个在$ [1,n] $范围内的,没有因数2和3的数$ d $,将它的倍数$ 2^a 3^b d $一起处 ...

  9. [OpenCV]OpenCV常用语法函数与坑点

    目录 1. 加载图像(cv::imread) 2. 显示图像(cv::nameWindows与cv::imshow) 3. 修改图像(cv::cvtColor) 4. 保存图像(cv::imwrite ...

  10. jdk官网历史版本下载&Oracle账号密码

    jdk官网下载地址: https://www.oracle.com/technetwork/java/javase/archive-139210.html 账号密码: 1772885836@qq.co ...