Skip to content

Commit 6a1bad5

Browse files
committed
2024-12-27 v. 7.5.1.1: small refactoring
1 parent ad71482 commit 6a1bad5

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

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 = '7.5.1'
8+
s.version = '7.5.1.1'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'

lib/common/linked_list.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def self.from_array(values)
2929
# @param {ListNode} second
3030
# @return {Boolean}
3131
def self.are_equals(first, second)
32-
return true if first.nil? && second.nil?
32+
return true if !first && !second
3333

34-
return false if first.nil? || second.nil?
34+
return false if !first || !second
3535

3636
first.val == second.val && are_equals(first.next, second.next)
3737
end

lib/common/list_node_with_random.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ def self.are_equal(l1, l2)
2626
l2 = l2.next
2727
end
2828

29-
l1.nil? && l2.nil?
29+
!l1 && !l2
3030
end
3131
end

lib/common/next_tree_node.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def self.are_equals(n1, n2)
2525
return are_equals(n1.left, n2.left) && are_equals(n1.right, n2.right)
2626
end
2727

28-
n1.nil? && n2.nil?
28+
!n1 && !n2
2929
end
3030

3131
# @param {NextTreeNode} other
@@ -40,7 +40,5 @@ def ==(other)
4040
end
4141

4242
# @return {Integer}
43-
def hash
44-
[val, left, right, nxt].hash
45-
end
43+
def hash = [val, left, right, nxt].hash
4644
end

lib/common/node_with_neighbors.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def initialize(val, neighbors = nil)
1515
# @param {NodeWithNeighbors} n2
1616
# @return {Boolean}
1717
def self.are_equals(n1, n2)
18-
if !n1.nil? && !n2.nil?
18+
if n1 && n2
1919
return false unless n1.val == n2.val
2020

2121
return false unless n1.neighbors.size == n2.neighbors.size
@@ -27,6 +27,6 @@ def self.are_equals(n1, n2)
2727
return true
2828
end
2929

30-
n1.nil? && n2.nil?
30+
!n1 && !n2
3131
end
3232
end

0 commit comments

Comments
 (0)