题目:

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

   Note:

    1. The given integer is guaranteed to fit within the range of a 32-bit signed integer.
    2. You could assume no leading zero bit in the integer’s binary representation.

   Example 1:

Input:
Output:
Explanation: The binary representation of is (no leading zero bits), and its complement is . So you need to output .

代码:

 class Solution {
public:
int findComplement(int num) {
int x = , p = ;
while(num){
if(num%==) x |= ( << p);
++p;
num/=;
}
return x;
}
};

LeetCode: 476 Number Complement(easy)的更多相关文章

  1. LeetCode#476 Number Complement - in Swift

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

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

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

  3. LeetCode 476. Number Complement

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

  4. LeetCode 476 Number Complement 解题报告

    题目要求 Given a positive integer, output its complement number. The complement strategy is to flip the ...

  5. 【leetcode】476. Number Complement

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

  6. 【LeetCode】476. Number Complement (java实现)

    原题链接 https://leetcode.com/problems/number-complement/ 原题 Given a positive integer, output its comple ...

  7. [LeetCode&Python] Problem 476. Number Complement

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

  8. 476. Number Complement

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

  9. 476. Number Complement 二进制中的相反对应数

    [抄题]: Given a positive integer, output its complement number. The complement strategy is to flip the ...

随机推荐

  1. kubernetes资源调度之LimitRange

    系列目录 LimitRange从字面意义上来看就是对范围进行限制,实际上是对cpu和内存资源使用范围的限制 前面我们讲到过资源配额,资源配额是对整个名称空间的资源的总限制,是从整体上来限制的,而Lim ...

  2. Activiti实战

    说实话,接触Activiti已经是3年前的事情,那时候组里想做一个流程自动化的application,并且记录用户点击.做单量等.第一次听说Activiti,感觉挺好奇的,遂看了下相关的文档跟同事的代 ...

  3. wmware搬家

    由于D盘空间不足D:\Users\Documents\Virtual Machines文件夹剪切至E:\Virtual Machines. 先关闭虚拟机 然后剪切 直接通过icon无法打开 先运行E: ...

  4. xcode打包 提交到iTunesConnect

    1.首先确定发布app的所必要选中或者切换的弄好 比如切换环境到 由测试环境切换到正式环境. 2.打发布包 首先选中Product 然后选中Archive. 3.等待编译. 4.打包成功 会进入到下面 ...

  5. 继承的文本框控件怎么响应EN_CHANGE等消息

    继承的文本框控件如何响应EN_CHANGE等消息?我从CEdit继承了一个CMyEdit类,想在这个类里填写它的一些消息.我在消息映射表里写的是MESSAGE_HANDLER(EN_CHANGE, O ...

  6. ajax跨域请求的问题

    使用getJson跨域请求,需要向服务器发送一个参数callback=? $.getJSON("http://appcenter.mobitide.com/admin/appSearch.p ...

  7. 九度OJ 1135:字符串排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1559 解决:807 题目描述: 先输入你要输入的字符串的个数.然后换行输入该组字符串.每个字符串以回车结束,每个字符串少于一百个字符. 如 ...

  8. LINUX上一个命令计算PI

    Linux上一个命令计算PI – 笑遍世界 http://smilejay.com/2017/11/calculate-pi-with-linux-command/ [root@d1 goEcho]# ...

  9. java的多生产者多消费者例子

    import java.util.concurrent.locks.*; public class Test9 { public static void main(String[] args) { / ...

  10. [SCOI2009] 最长距离

    题目描述 windy有一块矩形土地,被分为 NM 块 11 的小格子. 有的格子含有障碍物. 如果从格子A可以走到格子B,那么两个格子的距离就为两个格子中心的欧几里德距离. 如果从格子A不可以走到格子 ...