Skip to content

Commit 97ac74c

Browse files
authored
Merge pull request #5 from LuaanNguyen/daily-leetcode-2425
Daily LeetCode 2425
2 parents b58d09e + 4273440 commit 97ac74c

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ go test ./easy/0001_two_sum
3636
| [2116](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/description/?envType=daily-question&envId=2025-01-12) | [Check if a Parentheses String Can Be Valid](/medium/2116_check_if_a_parentheses_string_can_be_valid) | Medium | _`Stack`_ _`String`_ _`Greedy`_ |
3737
| [3223](https://leetcode.com/problems/minimum-length-of-string-after-operations/description/?envType=daily-question&envId=2025-01-13) | [Minimum Length of String After Operations](/medium/2116_check_if_a_parentheses_string_can_be_valid) | Medium | _`HashTable`_ _`String`_ _`Counting`_ |
3838
| [2657](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/description/?envType=daily-question&envId=2025-01-14) | [Find the Prefix Common Array of Two Arrays](/medium/2657_find_the_prefix_common_array_of_two_arrays) | Medium | _`HashTable`_ _`Array`_ |
39-
| [2429](https://leetcode.com/problems/minimize-xor/description/?envType=daily-question&envId=2025-01-15) | [Minimize XOR](/medium/2429_minimize_XOR) | Medium | _`Bit Manupulation`_ |
39+
| [2429](https://leetcode.com/problems/minimize-xor/description/?envType=daily-question&envId=2025-01-15) | [Minimize XOR](/medium/2429_minimize_XOR) | Medium | _`Bit Manipulation`_ |
40+
| [2425](https://leetcode.com/problems/bitwise-xor-of-all-pairings/description/?envType=daily-question&envId=2025-01-16) | [Bitwise XOR of All Pairings](/medium/2429_minimize_XOR) | Medium | _`Bit Manipulation`_ _`Brain Teaser`_ |
4041

4142
## License 🪪
4243

easy/0392_is_subsequence/0392_is_subsequence_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ func TestIsSubsequence(t *testing.T) {
3030
}
3131
})
3232
}
33-
}
33+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package bitwise_XOR_of_all_pairings
2+
3+
func xorAllNums(nums1 []int, nums2 []int) int {
4+
len1 := len(nums1)
5+
len2 := len(nums2)
6+
7+
8+
freq := make(map[int]int)
9+
10+
for _, num := range nums1 {
11+
freq[num] += len2
12+
}
13+
14+
for _, num := range nums2 {
15+
freq[num] += len1
16+
}
17+
18+
res := 0
19+
for num, count := range freq {
20+
if count % 2 != 0 {
21+
res ^= num
22+
}
23+
}
24+
25+
return res
26+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package bitwise_XOR_of_all_pairings
2+
3+
import "testing"
4+
5+
func TestXorAllNums(t *testing.T) {
6+
tests := []struct {
7+
name string
8+
nums1 []int
9+
nums2 []int
10+
expectedResult int
11+
} {
12+
{
13+
name: "Test Case 1",
14+
nums1: []int{2,1,3},
15+
nums2: []int{10,2,5,0},
16+
expectedResult: 13,
17+
},
18+
{
19+
name: "Test Case 2",
20+
nums1: []int{1,2},
21+
nums2: []int{3,4},
22+
expectedResult: 0,
23+
},
24+
}
25+
26+
for _, test := range tests {
27+
t.Run(test.name, func(t *testing.T){
28+
got := xorAllNums(test.nums1, test.nums2)
29+
30+
if got != test.expectedResult {
31+
t.Errorf("xorAllNums(%v, %v) = %d; want = %d", test.nums1, test.nums2, got, test.expectedResult)
32+
}
33+
})
34+
}
35+
}

0 commit comments

Comments
 (0)