Skip to content

Commit 9f59a09

Browse files
committed
150125
1 parent 0cf5007 commit 9f59a09

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# leetcode submit region begin(Prohibit modification and deletion)
2+
class Solution:
3+
def minimizeXor(self, num1: int, num2: int) -> int:
4+
tot = bin(num2).count('1')
5+
num1 = f"{num1:032b}"
6+
ans = list(num1)
7+
free = []
8+
for i in range(32):
9+
if tot == 0:
10+
ans[i] = '0'
11+
free.append(i)
12+
elif ans[i] == '1':
13+
tot -= 1
14+
else:
15+
free.append(i)
16+
for i in range(tot):
17+
ans[free.pop()] = '1'
18+
return int("".join(ans), 2)
19+
20+
21+
# leetcode submit region end(Prohibit modification and deletion)
22+
23+
24+
class MinimizeXor(Solution):
25+
pass

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from leetcode.editor.en.Q3223.MinimumLengthOfStringAfterOperations import MinimumLengthOfStringAfterOperations
1+
from leetcode.editor.en.Q2429.MinimizeXor import MinimizeXor
22

33
if __name__ == '__main__':
4-
print(MinimumLengthOfStringAfterOperations().minimumLength("abaacbcbb"))
4+
print(MinimizeXor().minimizeXor(2, 5))

0 commit comments

Comments
 (0)