LeetCode 1009. Complement of Base 10 Integer

哔哩哔哩 2023-05-08 10:27:50

The complementof an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation.

For example, The integer 5is "101"in binary and its complementis "010"which is the integer 2.

Given an integer n, return its complement.


【资料图】

Example 1:

Input:n = 5

Output:2

Explanation:5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.

Example 2:

Input:n = 7

Output:0

Explanation:7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.

Example 3:

Input:n = 10

Output:5

Explanation:10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.

Constraints:

0 <= n < 109

就是先求出来这个数对应的二进制的数字,然后将二进制的1变成0,0变成1;再返回对应的十进制的数字,原理简单,但是我把0忽略了,所以fail一次;

下面是代码:

Runtime1 ms

Beats

20.95%

Memory39.8 MB

Beats

19.32%

Click the distribution chart to view more details

x

热门推荐

LeetCode 1009. Complement of Base 10 Integer

2023-05

数字翻番,经济快速回暖!26个省份用电量实现正增长|时快讯

2023-05

2022年成人高校招生录取开始

2023-05

“绵阳”健康快乐动起来 团结奋进谱新篇 要闻

2023-05

湖湘自然历丨复得返自然⑧ 东江湖畔的“华南第一松”你见过吗 当前速看

2023-05

杰普特:目前公司已与客户沟通下一代检测设备检测需求,同时公司也在持续接洽新客户

2023-05

齐齐哈尔理工职业学院是公办还是民办_齐齐哈尔理工职业学院|天天观天下

2023-05

胃康灵哪些胃病不宜吃_胃康灵的功能主治是什么-天天速看

2023-05

锚定资本新规导航仪 多家银行掐好时间规划路线图 全球热讯

2023-05

今日关注:魄组词语_魄组词是什么

2023-05

推荐阅读

小米开始在越南生产手机 此前主要在中国和印度

2022-07

市民仍需注意防暑降温 本周或有局地强对流天气

2022-07

内蒙古满洲里市启动第四轮大规模核酸检测

2021-12

微博博主“鹿道森”确认身亡 警方:排除他杀

2021-12

失联摄影师“鹿道森”确认身亡 尸体被打捞上岸

2021-12

黑龙江讷河第二轮全员核检结果皆为阴性

2021-12

2021天象剧场收官:月“会”群星、日全食、流星雨扎堆亮相

2021-12

陕西新增1例境外归国集中隔离期满确诊病例

2021-12

内蒙古新增本土确诊病例91例

2021-12

宁夏银川警方破获2起以“互联网+物流寄递”为模式的特大毒品案件

2021-12