mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
fix: adapt missing ruby style guide (#1216)
This commit is contained in:
@ -17,10 +17,10 @@ end
|
||||
|
||||
### 将列表反序列化为链表 ###
|
||||
def arr_to_linked_list(arr)
|
||||
head = current = ListNode.new arr[0]
|
||||
head = current = ListNode.new(arr[0])
|
||||
|
||||
for i in 1...arr.length
|
||||
current.next = ListNode.new arr[i]
|
||||
current.next = ListNode.new(arr[i])
|
||||
current = current.next
|
||||
end
|
||||
|
||||
|
||||
@ -37,8 +37,8 @@ def print_tree(root, prev=nil, is_right=false)
|
||||
return if root.nil?
|
||||
|
||||
prev_str = " "
|
||||
trunk = Trunk.new prev, prev_str
|
||||
print_tree root.right, trunk, true
|
||||
trunk = Trunk.new(prev, prev_str)
|
||||
print_tree(root.right, trunk, true)
|
||||
|
||||
if prev.nil?
|
||||
trunk.str = "———"
|
||||
@ -50,9 +50,9 @@ def print_tree(root, prev=nil, is_right=false)
|
||||
prev.str = prev_str
|
||||
end
|
||||
|
||||
show_trunk trunk
|
||||
show_trunk(trunk)
|
||||
puts " #{root.val}"
|
||||
prev.str = prev_str if prev
|
||||
trunk.str = " |"
|
||||
print_tree root.left, trunk, false
|
||||
print_tree(root.left, trunk, false)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user