Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '8.2.5.4'
s.version = '8.2.5.5'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
33 changes: 12 additions & 21 deletions test/easy/test_100_same_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ class SameTreeTest < ::Minitest::Test
def test_default_one
assert(
is_same_tree(
::TreeNode.new(
1,
::TreeNode.new(2),
::TreeNode.new(3)
::TreeNode.build_tree(
[1, 2, 3]
),
::TreeNode.new(
1,
::TreeNode.new(2),
::TreeNode.new(3)
::TreeNode.build_tree(
[1, 2, 3]
)
)
)
Expand All @@ -26,12 +22,11 @@ def test_default_one
def test_default_two
assert(
!is_same_tree(
::TreeNode.new(
::TreeNode.new(2)
::TreeNode.build_tree(
[1, 2]
),
::TreeNode.new(
nil,
::TreeNode.new(2)
::TreeNode.build_tree(
[1, nil, 2]
)
)
)
Expand All @@ -40,15 +35,11 @@ def test_default_two
def test_default_three
assert(
!is_same_tree(
::TreeNode.new(
1,
::TreeNode.new(2),
::TreeNode.new(1)
::TreeNode.build_tree(
[1, 2, 1]
),
::TreeNode.new(
1,
::TreeNode.new(1),
::TreeNode.new(2)
::TreeNode.build_tree(
[1, 1, 2]
)
)
)
Expand Down
28 changes: 4 additions & 24 deletions test/easy/test_101_symmetric_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,8 @@ class SymmetricTreeTest < ::Minitest::Test
def test_default_one
assert(
is_symmetric(
::TreeNode.new(
1,
::TreeNode.new(
2,
::TreeNode.new(3),
::TreeNode.new(4)
),
::TreeNode.new(
2,
::TreeNode.new(4),
::TreeNode.new(3)
)
::TreeNode.build_tree(
[1, 2, 2, 3, 4, 4, 3]
)
)
)
Expand All @@ -29,18 +19,8 @@ def test_default_one
def test_default_two
assert(
!is_symmetric(
::TreeNode.new(
1,
::TreeNode.new(
2,
nil,
::TreeNode.new(3)
),
::TreeNode.new(
2,
nil,
::TreeNode.new(3)
)
::TreeNode.build_tree(
[1, 2, 2, nil, 3, nil, 3]
)
)
)
Expand Down
16 changes: 4 additions & 12 deletions test/easy/test_104_maximum_depth_of_binary_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ def test_default_one
assert_equal(
3,
max_depth(
::TreeNode.new(
3,
::TreeNode.new(9),
::TreeNode.new(
20,
::TreeNode.new(15),
::TreeNode.new(7)
)
::TreeNode.build_tree(
[3, 9, 20, nil, nil, 15, 7]
)
)
)
Expand All @@ -27,10 +21,8 @@ def test_default_two
assert_equal(
2,
max_depth(
::TreeNode.new(
1,
nil,
::TreeNode.new(2)
::TreeNode.build_tree(
[1, nil, 2]
)
)
)
Expand Down
24 changes: 4 additions & 20 deletions test/easy/test_110_balanced_binary_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ class BalancedBinaryTreeTest < ::Minitest::Test
def test_default_one
assert(
is_balanced(
::TreeNode.new(
3,
::TreeNode.new(9),
::TreeNode.new(
20,
::TreeNode.new(15),
::TreeNode.new(7)
)
::TreeNode.build_tree(
[3, 9, 20, nil, nil, 15, 7]
)
)
)
Expand All @@ -25,18 +19,8 @@ def test_default_one
def test_default_two
assert(
!is_balanced(
::TreeNode.new(
1,
::TreeNode.new(
2,
::TreeNode.new(
3,
::TreeNode.new(4),
::TreeNode.new(4)
),
::TreeNode.new(3)
),
::TreeNode.new(2)
::TreeNode.build_tree(
[1, 2, 2, 3, 3, nil, nil, 4, 4]
)
)
)
Expand Down
28 changes: 4 additions & 24 deletions test/easy/test_111_minimum_depth_of_binary_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ def test_default_one
assert_equal(
2,
min_depth(
::TreeNode.new(
3,
::TreeNode.new(9),
::TreeNode.new(
20,
::TreeNode.new(15),
::TreeNode.new(7)
)
::TreeNode.build_tree(
[3, 9, 20, nil, nil, 15, 7]
)
)
)
Expand All @@ -27,22 +21,8 @@ def test_default_two
assert_equal(
5,
min_depth(
::TreeNode.new(
2,
nil,
::TreeNode.new(
3,
nil,
::TreeNode.new(
4,
nil,
::TreeNode.new(
5,
nil,
::TreeNode.new(6)
)
)
)
::TreeNode.build_tree(
[2, nil, 3, nil, 4, nil, 5, nil, 6]
)
)
)
Expand Down
27 changes: 4 additions & 23 deletions test/easy/test_112_path_sum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,8 @@ class PathSumTest < ::Minitest::Test
def test_default_one
assert(
has_path_sum(
::TreeNode.new(
5,
::TreeNode.new(
4,
::TreeNode.new(
11,
::TreeNode.new(7),
::TreeNode.new(2)
)
),
::TreeNode.new(
8,
::TreeNode.new(13),
::TreeNode.new(
4,
nil,
::TreeNode.new(1)
)
)
::TreeNode.build_tree(
[5, 4, 8, 11, nil, 13, 4, 7, 2, nil, nil, nil, 1]
),
22
)
Expand All @@ -37,10 +20,8 @@ def test_default_one
def test_default_two
assert(
!has_path_sum(
::TreeNode.new(
1,
::TreeNode.new(2),
::TreeNode.new(3)
::TreeNode.build_tree(
[1, 2, 3]
),
5
)
Expand Down
13 changes: 5 additions & 8 deletions test/easy/test_144_binary_tree_preorder_traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ def test_default_one
assert_equal(
[1, 2, 3],
preorder_traversal(
::TreeNode.new(
1,
nil,
::TreeNode.new(
2,
::TreeNode.new(3)
)
::TreeNode.build_tree(
[1, nil, 2, 3]
)
)
)
Expand All @@ -33,7 +28,9 @@ def test_default_three
assert_equal(
[1],
preorder_traversal(
::TreeNode.new(1)
::TreeNode.build_tree(
[1]
)
)
)
end
Expand Down
13 changes: 5 additions & 8 deletions test/easy/test_145_binary_tree_postorder_traversal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ def test_default_one
assert_equal(
[3, 2, 1],
postorder_traversal(
::TreeNode.new(
1,
nil,
::TreeNode.new(
2,
::TreeNode.new(3)
)
::TreeNode.build_tree(
[1, nil, 2, 3]
)
)
)
Expand All @@ -33,7 +28,9 @@ def test_default_three
assert_equal(
[1],
postorder_traversal(
::TreeNode.new(1)
::TreeNode.build_tree(
[1]
)
)
)
end
Expand Down
40 changes: 8 additions & 32 deletions test/easy/test_226_invert_binary_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,12 @@ class InvertBinaryTreeTest < ::Minitest::Test
def test_default_one
assert(
::TreeNode.are_equals(
::TreeNode.new(
4,
::TreeNode.new(
7,
::TreeNode.new(9),
::TreeNode.new(6)
),
::TreeNode.new(
2,
::TreeNode.new(3),
::TreeNode.new(1)
)
::TreeNode.build_tree(
[4, 7, 2, 9, 6, 3, 1]
),
invert_tree(
::TreeNode.new(
4,
::TreeNode.new(
2,
::TreeNode.new(1),
::TreeNode.new(3)
),
::TreeNode.new(
7,
::TreeNode.new(6),
::TreeNode.new(9)
)
::TreeNode.build_tree(
[4, 2, 7, 1, 3, 6, 9]
)
)
)
Expand All @@ -44,16 +24,12 @@ def test_default_one
def test_default_two
assert(
::TreeNode.are_equals(
::TreeNode.new(
2,
::TreeNode.new(1),
::TreeNode.new(3)
::TreeNode.build_tree(
[2, 3, 1]
),
invert_tree(
::TreeNode.new(
2,
::TreeNode.new(3),
::TreeNode.new(1)
::TreeNode.build_tree(
[2, 1, 3]
)
)
)
Expand Down
14 changes: 5 additions & 9 deletions test/easy/test_257_binary_tree_paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ def test_default_one
assert_equal(
%w[1->2->5 1->3],
binary_tree_paths(
::TreeNode.new(
1,
::TreeNode.new(
2,
nil,
::TreeNode.new(5)
),
::TreeNode.new(3)
::TreeNode.build_tree(
[1, 2, 3, nil, 5]
)
)
)
Expand All @@ -27,7 +21,9 @@ def test_default_two
assert_equal(
['1'],
binary_tree_paths(
::TreeNode.new(1)
::TreeNode.build_tree(
[1]
)
)
)
end
Expand Down
Loading
Loading