Skip to content

Commit 4525150

Browse files
committed
Jan 15
1 parent b0f57bd commit 4525150

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution:
2+
def minimizeXor(self, num1: int, num2: int) -> int:
3+
n1, n2 = num1.bit_count(), num2.bit_count()
4+
res = num1
5+
for i in range(32):
6+
if n1 > n2 and (1 << i) & num1 > 0:
7+
res ^= 1 << i
8+
n1 -= 1
9+
if n1 < n2 and (1 << i) & num1 == 0:
10+
res ^= 1 << i
11+
n1 += 1
12+
return res
13+
14+
15+
def main():
16+
num1 = 3
17+
num2 = 5
18+
assert Solution().minimizeXor(num1, num2) == 3
19+
20+
num1 = 1
21+
num2 = 12
22+
assert Solution().minimizeXor(num1, num2) == 3
23+
24+
25+
if __name__ == '__main__':
26+
main()

2025-01-January-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
| January 12 | [2116. Check if a Parentheses String Can Be Valid](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | Medium | Unsolved |
1818
| January 13 | [3223. Minimum Length of String After Operations](https://leetcode.com/problems/minimum-length-of-string-after-operations/) | Medium | Solved |
1919
| January 14 | [2657. Find the Prefix Common Array of Two Arrays](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | Medium | Solved |
20-
| January 15 | []() | | |
20+
| January 15 | [2429. Minimize XOR](https://leetcode.com/problems/minimize-xor/) | Medium | Unsolved |
2121
| January 16 | []() | | |
2222
| January 17 | []() | | |
2323
| January 18 | []() | | |
@@ -40,5 +40,5 @@
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
4242
| Easy | 4 | 4 | 0 |
43-
| Medium | 10 | 9 | 1 |
43+
| Medium | 11 | 9 | 2 |
4444
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)