From 189a8b50bab547347549eebd42e95f51a57ebc07 Mon Sep 17 00:00:00 2001 From: fartem Date: Thu, 16 Jan 2025 08:05:49 +0300 Subject: [PATCH 1/2] 2025-01-16 v. 8.1.0: added "2425. Bitwise XOR of All Pairings" --- README.md | 1 + leetcode-ruby.gemspec | 2 +- .../2425_bitwise_xor_of_all_pairings.rb | 19 +++++++++++++ .../test_2425_bitwise_xor_of_all_pairings.rb | 27 +++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 lib/medium/2425_bitwise_xor_of_all_pairings.rb create mode 100644 test/medium/test_2425_bitwise_xor_of_all_pairings.rb diff --git a/README.md b/README.md index fae734da..a31af4e2 100644 --- a/README.md +++ b/README.md @@ -648,6 +648,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 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) | | 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) | | 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) | +| 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) | | 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) | | 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) | | 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) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index 523a86c9..a1e50d03 100644 --- a/leetcode-ruby.gemspec +++ b/leetcode-ruby.gemspec @@ -5,7 +5,7 @@ require 'English' ::Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0' s.name = 'leetcode-ruby' - s.version = '8.0.9' + s.version = '8.1.0' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/medium/2425_bitwise_xor_of_all_pairings.rb b/lib/medium/2425_bitwise_xor_of_all_pairings.rb new file mode 100644 index 00000000..e35b0baa --- /dev/null +++ b/lib/medium/2425_bitwise_xor_of_all_pairings.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# https://leetcode.com/problems/bitwise-xor-of-all-pairings/ +# @param {Integer[]} nums1 +# @param {Integer[]} nums2 +# @return {Integer} +def xor_all_nums(nums1, nums2) + c1 = nums1.size + c2 = nums2.size + + x1 = 0 + x2 = 0 + + nums2.each { |num| x2 ^= num } if c1.odd? + + nums1.each { |num| x1 ^= num } if c2.odd? + + x1 ^ x2 +end diff --git a/test/medium/test_2425_bitwise_xor_of_all_pairings.rb b/test/medium/test_2425_bitwise_xor_of_all_pairings.rb new file mode 100644 index 00000000..31802267 --- /dev/null +++ b/test/medium/test_2425_bitwise_xor_of_all_pairings.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require_relative '../../lib/medium/2425_bitwise_xor_of_all_pairings' +require 'minitest/autorun' + +class MinimizeXORTest < ::Minitest::Test + def test_default_one + assert_equal( + 13, + xor_all_nums( + [2, 1, 3], + [10, 2, 5, 0] + ) + ) + end + + def test_default_two + assert_equal( + 0, + xor_all_nums( + [1, 2], + [3, 4] + ) + ) + end +end From 69aee28801ae9a65e41d39dabb7314e98e78efdd Mon Sep 17 00:00:00 2001 From: fartem Date: Thu, 16 Jan 2025 08:05:56 +0300 Subject: [PATCH 2/2] 2025-01-16 v. 8.1.0: added "2425. Bitwise XOR of All Pairings" --- test/medium/test_2425_bitwise_xor_of_all_pairings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/medium/test_2425_bitwise_xor_of_all_pairings.rb b/test/medium/test_2425_bitwise_xor_of_all_pairings.rb index 31802267..3a550ac0 100644 --- a/test/medium/test_2425_bitwise_xor_of_all_pairings.rb +++ b/test/medium/test_2425_bitwise_xor_of_all_pairings.rb @@ -4,7 +4,7 @@ require_relative '../../lib/medium/2425_bitwise_xor_of_all_pairings' require 'minitest/autorun' -class MinimizeXORTest < ::Minitest::Test +class BitwiseXOROfAllPairingsTest < ::Minitest::Test def test_default_one assert_equal( 13,