国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

476. Number Complement

2019-11-08 02:58:28
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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: 5Output: 2Explanation: 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: 1Output: 0Explanation: 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) { long long mode = 1; int ans = num; while(num){ mode <<= 1; num >>= 1; } --mode; ans ^= mode; return ans; }};
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 台北市| 福海县| 申扎县| 革吉县| 余干县| 阿巴嘎旗| 三都| 东阳市| 常宁市| 阿拉尔市| 肇州县| 绥化市| 凉山| 平顶山市| 岳西县| 文安县| 铅山县| 永济市| 冷水江市| 蚌埠市| 浙江省| 和田市| 万年县| 海原县| 延吉市| 措美县| 天等县| 遂溪县| 恩施市| 崇左市| 简阳市| 宁波市| 祁门县| 大荔县| 南召县| 定边县| 苏尼特左旗| 社旗县| 潜江市| 灵川县| 岚皋县|