NB
Size: a a a
NB
VS
NB
M
NB
VS
NB
ArgumentError
VS
NB
I
r
M
M
def valid_time(time)
Time.strptime(time, '%Y-%m-%d %H:%M:%S').present?
rescue ArgumentError
false
end
M
D
def merge_k_lists(lists)
arr = []
# fill array
lists.each do |x|
while x do
arr.push(x)
x = x.next
end
end
arr.sort_by!{|x| x.val}
return nil if arr.empty?
head = arr[0]
cur = arr[1]
head.next = cur
i = 2
while cur
cur.next = arr[i]
cur = arr[i]
i += 1
end
head
end
I
PM
def merge_k_lists(lists)
arr = []
# fill array
lists.each do |x|
while x do
arr.push(x)
x = x.next
end
end
arr.sort_by!{|x| x.val}
return nil if arr.empty?
head = arr[0]
cur = arr[1]
head.next = cur
i = 2
while cur
cur.next = arr[i]
cur = arr[i]
i += 1
end
head
end
D
# https://leetcode.com/problems/merge-k-sorted-lists/submissions/
# Runtime: 56 ms, faster than 72.99% of Ruby online submissions for Merge k Sorted Lists.
# Memory Usage: 10.4 MB, less than 100.00% of Ruby online submissions for Merge k Sorted Lists
D