题目:

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. ubuntu 下的中文输入法的安装和配置- ibus

    ibus输入法 Chinese语言包安装 首先需要给Ubuntu16.04安装Chinese语言包支持.  如上图点击其中的Install/Remove Languages…,这个对话框是通过syst ...

  2. adb tcp 调试

    su setprop service.adb.tcp.port 5555 stop adbd start adbd

  3. 04 svn设置开机启动

    一:设置开机启动[dos命令] 格式: sc create 服务名称 binPath=空格"安装目录/svnserve.exe -r 版本库地址目录 --service" star ...

  4. 安卓Android手机直播推送同步录像功能设计与实现源码

    本文转自:http://blog.csdn.net/jyt0551/article/details/58714595 EasyPusher是一款非常棒的推送客户端.稳定.高效.低延迟,音视频同步等都特 ...

  5. Net Core环境开发与调试

    NET Core 包括.NET Core Runtime 和 .NET Core SDK: .NET Core = 应用运行依赖的 .NET Core Runtime .NET Core SDK = ...

  6. (t,p,o) t:p>=o there cannot be more consumer instances in a consumer group than partitions

    https://kafka.apache.org/intro.html Kafka as a Messaging System How does Kafka's notion of streams c ...

  7. struts2的核心和工作原理 (转)

    转自--------http://blog.csdn.net/laner0515/article/details/27692673 在学习struts2之前,首先我们要明白使用struts2的目的是什 ...

  8. asp概述

    asp的理解 今天才知道,Asp原来不是一种语言,也不是一种开发工具,而是一种技术框架, 主要功能是把脚本语言,HTML,组件和Web数据库访问功能有机的结合在一起, 形成一个能在服务器端运行的应用程 ...

  9. Oracle序列更新

    Oracle 数据库的时候,有时候会选择使用自增序列作为主键.但是在开发过程中往往会遇到一些不规范的操作,导致表的主键值不是使用序列插入的.这样在数据移植的时候就会出现各种各样的问题.当然数据库主键不 ...

  10. mac安装python3

    http://www.jianshu.com/p/51811fa24752 brew install python3 安装路径:/usr/local/Cellar 使用: 执行python3即可 配置 ...