题目:

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. Java 序列化Serializable具体解释(附具体样例)

    Java 序列化Serializable具体解释(附具体样例) 1.什么是序列化和反序列化 Serialization(序列化)是一种将对象以一连串的字节描写叙述的过程:反序列化deserializa ...

  2. 科学计算 | Matlab 使用 GPU 并行计算

    科学计算 | Matlab 使用 GPU 并行计算 本文转载自:  https://sanwen8.cn/p/14bJc10.html       Matlab下直接使用GPU并行计算(预告)< ...

  3. 搭建基于Jenkins的CI服务器

    安装Jenkins和创建任务这些操作网上一搜一大把,这里就没必要写了,直接就开始编译.单元测试,覆盖,git提交触发构建,构建失败发送给提交人邮件. 因为项目比较复杂,为了懒省事我直接在CI服务器上安 ...

  4. 果壳、推库、虎秀、知乎、it世界

    果壳.推库.虎秀.知乎.it世界

  5. wince c# 创建桌面快捷方式 .

    static void Create() { string PathGPRS = System.IO.Path.GetDirectoryName(System.Reflection.Assembly. ...

  6. EasyDarwin开源手机直播方案:EasyPusher手机直播推送,EasyDarwin流媒体服务器,EasyPlayer手机播放器

    在不断进行EasyDarwin开源流媒体服务器的功能和性能完善的同时,我们也配套实现了目前在安防和移动互联网行业比较火热的移动端手机直播方案,主要就是我们的 EasyPusher直播推送项目 和 Ea ...

  7. SQuirreL – Phoenix的GUI

    本文主要介绍如何通过SQuirreL访问Phoenix,以及如何在SQuirreL中配置Phoenix参数. 什么是SQuirrel? SQuirreL SQL Client是一个开源免费软件, 可以 ...

  8. jQuery 给div绑定单击事件

    说明:这篇随笔介绍的是怎么给div添加单击(click)事件.不再废话 直接看代码 <%@ Page Language="C#" AutoEventWireup=" ...

  9. less 一种 动态 样式 语言

    LESS « 一种动态样式语言 http://www.bootcss.com/p/lesscss/ 一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承,运算, 函数 ...

  10. Date日期转字符创格式的日期

    public static void main(String[] args) { SimpleDateFormat dateFormater = new SimpleDateFormat(" ...