Bit Manipulation-476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.
Note:
- The given integer is guaranteed to fit within the range of a 32-bit signed integer.
- You could assume no leading zero bit in the integer’s binary representation.
Example 1:
Input: 5
Output: 2
Explanation: The binary representation of 5 is 101 (no leading zero bits), and its complement is 010. So you need to output 2.
Example 2:
Input: 1
Output: 0
Explanation: The binary representation of 1 is 1 (no leading zero bits), and its complement is 0. So you need to output 0.
class Solution {
public:
int findComplement(int num) {
int n=,cp,ans;
cp=num;
int m=;
while(cp!=){
cp=cp/;m=m*;
}
ans=m--num;
return ans;
}
};
Bit Manipulation-476. Number Complement的更多相关文章
- 【leetcode】476. Number Complement
problem 476. Number Complement solution1: class Solution { public: int findComplement(int num) { //正 ...
- LeetCode#476 Number Complement - in Swift
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
- LeetCode 476. Number Complement (数的补数)
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
- LeetCode 476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
- 476. Number Complement
题目 Given a positive integer, output its complement number. The complement strategy is to flip the bi ...
- 【LeetCode】476. Number Complement (java实现)
原题链接 https://leetcode.com/problems/number-complement/ 原题 Given a positive integer, output its comple ...
- LeetCode 476 Number Complement 解题报告
题目要求 Given a positive integer, output its complement number. The complement strategy is to flip the ...
- [LeetCode&Python] Problem 476. Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
- 476. Number Complement 二进制中的相反对应数
[抄题]: Given a positive integer, output its complement number. The complement strategy is to flip the ...
- LeetCode: 476 Number Complement(easy)
题目: Given a positive integer, output its complement number. The complement strategy is to flip the b ...
随机推荐
- linux-git服务搭建
第一步,安装git: 源码安装参考:http://www.cnblogs.com/syuf/p/9151115.html 第二步,创建一个git用户,用来运行git服务: $ sudo adduser ...
- PHP在win7安装Phalcon框架
我的环境是64位的 Win7. 安装 Phalcon 也极其简单,只需要下载一个文件(php_phalcon.dll), 要以 phpinfo() 里面“Architecture”属性为准! 下载地址 ...
- 201621123008《Java程序设计》第七周学习总结
1. 本周学习总结 1.1 思维导图:Java图形界面总结 2.书面作业 1. GUI中的事件处理 1.1 写出事件处理模型中最重要的几个关键词. 监听,事件源,事件,注册. 1.2 任意编写事件处理 ...
- OSGi 系列(三)之 bundle 事件监听
OSGi 系列(三)之 bundle 事件监听 bundle 的事件监听是在 bundle 生命周期的不同状态相互转换时,OSGi 框架会发出各种不同的事件供事先注册好的事件监听器处理. 1. 事件监 ...
- centos7 rabbitmq安装以及应用
安装单机rabbitmq 1.安装erlang cd /usr.local yum install wget yum install net-tools wget http://erlang.or ...
- 2018.10.17 NOIP模拟 管道(状压dp)
传送门 状压dp好题. 怎么今天道道题都有点东西啊 对于今天题目神仙出题人先膜为上策:%%%%DzYoAk_UoI%%%% 设f[i][j]f[i][j]f[i][j]表示选取点的状态集合为iii,当 ...
- gj9 迭代器和生成器
9.1 python的迭代协议 list内部实现了__iter__()协议(魔法函数),是可迭代对象,但还不是迭代器(迭代器需要实现__next__协议) 生成器实现了__iter__(),__nex ...
- 用原生的javascript 实现一个无限滚动的轮播图
说一下思路:和我上一篇博客中用JQ去写的轮播图有相同点和不同点 相同点: 首先页面布局是一样的 同样是改变.inner盒子的位置去显示不同的图片 不同点: 为了实现无限滚动需要多添加两张重复的图片 左 ...
- (最小生成树)Agri-Net -- POJ -- 1258
链接: http://poj.org/problem?id=1258 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82831#probl ...
- C++ 11可变参数接口设计在模板编程中应用的一点点总结
概述 本人对模板编程的应用并非很深,若要用一句话总结我个人对模板编程的理解,我想说的是:模板编程是对类定义的弱化. 如何理解“类定义的弱化”? 一个完整的类有如下几部分组成: 类的名称: 类的成员变量 ...