小练习:补数 (Number Complement)
1.eamples
Input:
Output:
Explanation: The binary representation of is (no leading zero bits), and its complement is . So you need to output .
Input:
Output:
Explanation: The binary representation of is (no leading zero bits), and its complement is . So you need to output .
Subscribe to see which companies asked this question.
2.solve
class Solution {
public:
int findComplement(int num) {
int mask=;
int temp = num;
while(num)
{
num>>=;
mask<<=;
}
mask--;
return (temp^mask);
}
};
小练习:补数 (Number Complement)的更多相关文章
- [Swift]LeetCode476. 数字的补数 | Number Complement
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
- 【LeetCode】476. 数字的补数 Number Complement
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:Leetcode, 力扣,476, 补数,二进制,Pyth ...
- 【leetcode】476. Number Complement
problem 476. Number Complement solution1: class Solution { public: int findComplement(int num) { //正 ...
- LeetCode——Number Complement
LeetCode--Number Complement Question Given a positive integer, output its complement number. The com ...
- LeetCode_Easy_471:Number Complement
LeetCode_Easy_471:Number Complement 题目描述 Given a positive integer, output its complement number. The ...
- LeetCode_476. Number Complement
476. Number Complement Easy Given a positive integer, output its complement number. The complement s ...
- 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] Number Complement 补数
Given a positive integer, output its complement number. The complement strategy is to flip the bits ...
随机推荐
- mysql锁机制之乐观锁(二)
select for update: 在执行这个 select 查询语句的时候,会将对应的索引访问条目进行上排他锁(X 锁),也就是说这个语句对应的锁就相当于update带来的效果. select * ...
- 虚拟机Linux系统忘记密码的情况下,修改root或其他用户密码
使用场景 linux管理员忘记root密码,需要进行找回操作. 注意事项:本文基于centos7环境进行操作,由于centos的版本是有差异的,继续之前请确定好版本. 步骤 一.重启系统,在开机过程中 ...
- hive报错汇总
1.需要注意的是,要在namenode(超级用户)上操作,貌似是 hive> insert into table record_partition partition(trancation_da ...
- Web前端页面的浏览器兼容性测试心得(一)搭建测试用本地静态服务器
自从实习以来,我体验了由一个人编程再到多人协作编程的转换.同时也接触了很多新鲜事物,学到了很多东西.工作时,常常需要多个人协同测试一张H5页面(PC.手机.平板等跨设备测试),也会经常把页面给PM或老 ...
- Web开发相关笔记 #02#
[1] HTML 插入第三方. [2] [3] JavaScript 回调函数 & 模块化 --> 用变量封装数据.方法 --> 类比 Java 中的 package var fe ...
- git服务器-------》用户免密git操作
找到/etc/ssh/sshd_config文件 开启 RSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile .ss ...
- Web安全学习笔记之Openvas配置,使用,报告
OpenVAS(开放式漏洞评估系统)是一个客户端/服务器架构,它常用来评估目标主机上的漏洞.OpenVAS是Nessus项目的一个分支,它提供的产品是完全地免费.OpenVAS默认安装在标准的Kali ...
- No module named _tkinter
https://www.douban.com/note/524197380/?type=like
- 20145301 实验三 "敏捷开发与XP实践"
20145301 实验三 "敏捷开发与XP实践" 课程:Java程序设计 班级:1453 指导教师:娄嘉鹏 实验日期:2016.04.22 实验名称:敏捷开发与XP实践 一.实验 ...
- [译]JavaScript需要类吗?
[译]JavaScript需要类吗? 原文:http://www.nczonline.net/blog/2012/10/16/does-javascript-need-classes/ 译者注:在 ...