Skip to content

Commit f649a07

Browse files
committed
2025-03-12 v. 8.9.2: added "2007. Find Original Array From Doubled Array"
1 parent 38993d4 commit f649a07

4 files changed

+57
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
725725
| 1910. Remove All Occurrences of a Substring | [Link](https://leetcode.com/problems/remove-all-occurrences-of-a-substring/) | [Link](./lib/medium/1910_remove_all_occurrences_of_a_substring.rb) | [Link](./test/medium/test_1910_remove_all_occurrences_of_a_substring.rb) |
726726
| 1985. Find the Kth Largest Integer in the Array | [Link](https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/) | [Link](./lib/medium/1985_find_the_kth_largest_integer_in_the_array.rb) | [Link](./test/medium/test_1985_find_the_kth_largest_integer_in_the_array.rb) |
727727
| 1996. The Number of Weak Characters in the Game | [Link](https://leetcode.com/problems/the-number-of-weak-characters-in-the-game/) | [Link](./lib/medium/1996_the_number_of_weak_characters_in_the_game.rb) | [Link](./test/medium/test_1996_the_number_of_weak_characters_in_the_game.rb) |
728+
| 2007. Find Original Array From Doubled Array | [Link](https://leetcode.com/problems/find-original-array-from-doubled-array/) | [Link](./lib/medium/2007_find_original_array_from_doubled_array.rb) | [Link](./test/medium/test_2007_find_original_array_from_doubled_array.rb) |
728729
| 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) |
729730
| 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) |
730731
| 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) |

leetcode-ruby.gemspec

Lines changed: 1 addition & 1 deletion
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.9.1'
8+
s.version = '8.9.2'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/find-original-array-from-doubled-array/
4+
# @param {Integer[]} changed
5+
# @return {Integer[]}
6+
def find_original_array(changed)
7+
result = []
8+
q = []
9+
changed.sort!
10+
11+
changed.each do |num|
12+
if !q.empty? && num == q.first
13+
q.shift
14+
else
15+
q << num * 2
16+
result << num
17+
end
18+
end
19+
20+
q.empty? ? result : []
21+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/2007_find_original_array_from_doubled_array'
5+
require 'minitest/autorun'
6+
7+
class FindOriginalArrayFromDoubledArrayTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
[1, 3, 4],
11+
find_original_array(
12+
[1, 3, 4, 2, 6, 8]
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
[],
20+
find_original_array(
21+
[6, 3, 0, 1]
22+
)
23+
)
24+
end
25+
26+
def test_default_three
27+
assert_equal(
28+
[],
29+
find_original_array(
30+
[]
31+
)
32+
)
33+
end
34+
end

0 commit comments

Comments
 (0)