# Definition for singly-linked list.
# class ListNode
#     attr_accessor :val, :next
#     def initialize(val = 0, _next = nil)
#         @val = val
#         @next = _next
#     end
# end
# @param {ListNode} l1
# @param {ListNode} l2
# @return {ListNode}
def add_two_numbers(l1, l2)
    ans = 0
    i = 0

    while true
        break if l1.nil? && l2.nil?
        
        ans += ((l1&.val || 0) + (l2&.val || 0)) * 10 ** i
        i += 1
        
        l1 = l1&.next
        l2 = l2&.next
    end
    
    list = []
    while true
        list.append(ans % 10)
        ans /= 10
        break if ans == 0
    end
    return list
end