Fix inconsistent comments Ruby - chapter array and linked list (#1202)

* fix: inconsistent comments Ruby - chapter array and linked list

* fix: better Ruby code & comments
This commit is contained in:
khoaxuantu
2024-03-31 14:58:35 +07:00
committed by GitHub
parent 57bdfd6284
commit 5ce088de52
3 changed files with 15 additions and 15 deletions

View File

@@ -9,8 +9,8 @@ class ListNode
attr_accessor :val # 节点值
attr_accessor :next # 指向下一节点的引用
def initialize(val=nil, next_node=nil)
@val = val || 0
def initialize(val=0, next_node=nil)
@val = val
@next = next_node
end
end
@@ -23,7 +23,7 @@ def arr_to_linked_list(arr)
current.next = ListNode.new arr[i]
current = current.next
end
head
end