国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 金秀| 济阳县| 华蓥市| 合江县| 梓潼县| 陆丰市| 观塘区| 岳池县| 洪泽县| 广宁县| 临城县| 清丰县| 铜川市| 洛隆县| 云龙县| 吉木萨尔县| 独山县| 金溪县| 民和| 金堂县| 灵丘县| 马边| 靖边县| 高清| 长宁区| 营口市| 封开县| 沙洋县| 阳新县| 南雄市| 思茅市| 桂林市| 洪湖市| 哈尔滨市| 嘉鱼县| 桑日县| 台北县| 安平县| 长垣县| 黔西| 乐昌市|