Skip to content

Commit 599fd86

Browse files
authored
2025-01-16 v. 8.1.0: added "2425. Bitwise XOR of All Pairings"
2 parents 07e3fc3 + 69aee28 commit 599fd86

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
648648
| 951. Flip Equivalent Binary Trees | [Link](https://leetcode.com/problems/flip-equivalent-binary-trees/) | [Link](./lib/medium/951_flip_equivalent_binary_trees.rb) | [Link](./test/medium/test_951_flip_equivalent_binary_trees.rb) |
649649
| 1400. Construct K Palindrome Strings | [Link](https://leetcode.com/problems/construct-k-palindrome-strings/) | [Link](./lib/medium/1400_construct_k_palindrome_strings.rb) | [Link](./test/medium/test_1400_construct_k_palindrome_strings.rb) |
650650
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
651+
| 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) |
651652
| 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) |
652653
| 2657. Find the Prefix Common Array of Two Arrays | [Link](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | [Link](./lib/medium/2657_find_the_prefix_common_array_of_two_arrays.rb) | [Link](./test/medium/test_2657_find_the_prefix_common_array_of_two_arrays.rb) |
653654
| 3223. Minimum Length of String After Operations | [Link](https://leetcode.com/problems/minimum-length-of-string-after-operations/) | [Link](./lib/medium/3223_minimum_length_of_string_after_operations.rb) | [Link](./test/medium/test_3223_minimum_length_of_string_after_operations.rb) |

leetcode-ruby.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '8.0.9'
8+
s.version = '8.1.0'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/bitwise-xor-of-all-pairings/
4+
# @param {Integer[]} nums1
5+
# @param {Integer[]} nums2
6+
# @return {Integer}
7+
def xor_all_nums(nums1, nums2)
8+
c1 = nums1.size
9+
c2 = nums2.size
10+
11+
x1 = 0
12+
x2 = 0
13+
14+
nums2.each { |num| x2 ^= num } if c1.odd?
15+
16+
nums1.each { |num| x1 ^= num } if c2.odd?
17+
18+
x1 ^ x2
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/2425_bitwise_xor_of_all_pairings'
5+
require 'minitest/autorun'
6+
7+
class BitwiseXOROfAllPairingsTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
13,
11+
xor_all_nums(
12+
[2, 1, 3],
13+
[10, 2, 5, 0]
14+
)
15+
)
16+
end
17+
18+
def test_default_two
19+
assert_equal(
20+
0,
21+
xor_all_nums(
22+
[1, 2],
23+
[3, 4]
24+
)
25+
)
26+
end
27+
end

0 commit comments

Comments
 (0)