File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 1
- from leetcode .editor .en .Q3223 . MinimumLengthOfStringAfterOperations import MinimumLengthOfStringAfterOperations
1
+ from leetcode .editor .en .Q2429 . MinimizeXor import MinimizeXor
2
2
3
3
if __name__ == '__main__' :
4
- print (MinimumLengthOfStringAfterOperations ().minimumLength ( "abaacbcbb" ))
4
+ print (MinimizeXor ().minimizeXor ( 2 , 5 ))
You can’t perform that action at this time.
0 commit comments