[Lintcode]181. Flip Bits
发布时间:2020-12-14 04:25:28 所属栏目:大数据 来源:网络整理
导读:181. Flip Bits 本题难度: Easy Topic: MathBit Manipulation Description Determine the number of bits required to flip if you want to convert integer n to integer m. Example Given n = 31 (22222),m = 14 (01110),return 2. Notice Both n and m ar
181. Flip Bits
Example Notice 我的代码class Solution: """ @param a: An integer @param b: An integer @return: An integer """ def bitSwapRequired(self,a,b): # write your code here ff=pow(2,32)#注意负数 a_r = (a + ff)%ff b_r = (b + ff)%ff count = 0 while ((a_r or b_r) != 0): a_b = a_r % 2 b_b = b_r % 2 count += (a_b != b_b) a_r = a_r // 2 b_r = b_r // 2 return count 思路
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |