class Solution:
def bitwiseComplement(self, N: int) -> int:
if N==0:
return 1
elif N==1:
return 0 s = list()
while N!=0:
re = N%2
if re==0:
re=1
else:
re = 0
s.append(re)
N=N//2
sums = 0
for i in range(len(s)):
cur = int(s[i])
cur = cur * pow(2,i)
sums +=cur
return sums

leetcode1009的更多相关文章

  1. [Swift]LeetCode1009. 十进制整数的补码 | Complement of Base 10 Integer

    Every non-negative integer N has a binary representation.  For example, 5 can be represented as &quo ...

随机推荐

  1. 【支付专区】之解析微信支付返回xml

    public static Map<String,Object> parseBodyXml2Map(String xml){ Map<String,Object> map = ...

  2. Hard commits, soft commits and transaction logs

    “Hard commits are about durability, soft commits are about visibility“  Transaction Logs 首先介绍下solrcl ...

  3. 力奋github:https://github.com/birdstudiocn

    我的github地址https://github.com/birdstudiocn

  4. 筛选法求n以内所有的素数

    求n以内所有的素数? 筛选法:将2到n中所有的数都列出来,然后从2开始,先化掉所有2的倍数,然后每次从下一个剩下的数(必然是素数)开始,划掉其内所有的倍数,最后剩下来的数就都是素数 例:13  红色为 ...

  5. undefined reference to `__isnan'

    sjs@sjs-virtual-machine:~/work/Onvif$ arm-hisiv100nptl-linux-gcc *.c -lpthread -static -o ../../nfsm ...

  6. HBase - Filter - 过滤器的介绍以及使用

    1 过滤器HBase 的基本 API,包括增.删.改.查等.增.删都是相对简单的操作,与传统的 RDBMS 相比,这里的查询操作略显苍白,只能根据特性的行键进行查询(Get)或者根据行键的范围来查询( ...

  7. 关于string.Template的简单介绍

    一.简介 string模块定义了一种新字符串类型Template,它简化了特定的字符串置换操作. 何谓“简化”?我们可以先想一下我们之前比较常用的有关字符串的“置换”操作有哪些:一种是利用%操作符实现 ...

  8. [UE4]认识Decorator

    Decorator装饰器:即为其他行为树系统中的条件语句,附着于一个Composite(组合节点)或者Task(任务节点),并定义树中的一个分支或者单个节点是否可被执行. Decorator装饰器节点 ...

  9. c#第一周的游戏

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  10. sas 日期比较代码备忘

    DATA A;    SET S.payrecordinfo;    YY=DATEPART(AddTime);    FORMAT YY MMDDYY10.;RUN; DATA A1;    SET ...