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 ...
随机推荐
- 在iframe框架中全屏不好使的原因
遇到的问题:我是在iframe框架中添加了一个插件在360和火狐中不好使,将allowfullscreen="true" 属性配置好就没问题了: 可能出现的原因:将allowful ...
- 3.说一下你了解的弹性FLEX布局.
页面布局一直都是web应用样式设计的重点 我们传统的布局方式都是基于盒模型的 利用display.position.float来布局有一定局限性 比如说实现自适应垂直居中 随着响应式布局的流行,CSS ...
- HDOJ1242 Rescue(营救) 搜索
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- htons、htonl与字节序大小端
判断字节序大小端code #include <stdio.h> int main() { ) == ) printf("big endian\n"); else pri ...
- 第十届Mockplus ▪ UXPA用户体验西南赛区决赛成功举行
九月的重庆,秋意渐浓. 伴随着凉爽的秋风,第十届Mockplus·UXPA国际用户体验创新大赛(UXD Award2018)西南赛区决赛于9月16日下午在四川美术学院-虎溪校区成功举办.来自西南区域各 ...
- httpclient学习(原创)
--httpmime-4.2.5.jar 跟提交Form相关的类 这一块主要post数据的提交.每一条数据同name和content组成.content可能是字节数组或是流.提交这一类(MIME)的 ...
- github 如何添加项目代码
1.点添加一个resporitory 2.添加的时候一定要选上下面的添加readme这个选项 3.点进去点code就能create file了.贴上代码就行.主要是第二步必须选对
- 从一个流中读数据--fread
头文件:#include<stdio.h> 函数原型:int fread(void *ptr,int size,int nitems,FILE *stream); 参数说明: ptr:用于 ...
- 2018.07.08 NOIP模拟 第K小数(二分)
第K小数 题目背景 SOURCE:NOIP2016-AHSDFZ T1 题目描述 有两个正整数数列,元素个数分别为 N 和 M .从两个数列中分别任取一个数相乘,这样一共可以得到 N*M 个数,询问这 ...
- 34.More-healthyful Menu Options for Kids 给孩子提供的更健康菜式选择
34.More-healthyful Menu Options for Kids 给孩子提供的更健康菜式选择 ① French fries,washed down with a pint of sod ...