Runtime error in Go?

  • 0


    I am getting a runtime error on my Go solution which I don't understand. Here is the function:

    func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
    	res := &ListNode{}
    	curr := res
    	l1 = &ListNode{Next: l1}
    	l2 = &ListNode{Next: l2}
    	for *l1.Next != (ListNode{}) {
    		l1 = l1.Next
    		l2 = l2.Next
    		sum := curr.Val + l1.Val + l2.Val
    		mod := sum % 10
    		curr.Val = mod
    		curr.Next = &ListNode{}
    		curr = curr.Next
    		curr.Val = (sum - mod) / 10
    	return res

    The thing is that that leetcode doesn't give me the error, it just tells me that the result is empty. Here is the working code on the Go playground. Can anyone see the error, what have I done wrong?

    Thank you!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.