-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path1318.py
36 lines (34 loc) · 1.11 KB
/
1318.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
__________________________________________________________________________________________________
sample 12 ms submission
class Solution:
def minFlips(self, a, b, c):
xor = b ^ c
g = xor & ~a
t = a & ~c
h = t & b
sum1 = g | h
str_1 = str(bin(t))[2:]
str_2 = str(bin(sum1))[2:]
final_1 = map(lambda x: int(x), str_1)
final_2 = map(lambda x: int(x), str_2)
return sum(final_1) + sum(final_2)
__________________________________________________________________________________________________
sample 16 ms submission
class Solution:
def minFlips(self, a: int, b: int, c: int) -> int:
m=[2**(30-i) for i in range(31)]
ans=0
for i in range(31):
xa=a//m[i]
a%=m[i]
xb=b//m[i]
b%=m[i]
xc=c//m[i]
c%=m[i]
print(xa,xb,xc)
if xc==1 and xa+xb==0:
ans+=1
elif xc==0:
ans+=xa+xb
return ans
__________________________________________________________________________________________________