> For the complete documentation index, see [llms.txt](https://leetcode.realtemirov.uz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leetcode.realtemirov.uz/problems/2.-add-two-numbers.md).

# 2. Add Two Numbers

🟧 Medium

## Solution

My Solution

```go
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
    head := &ListNode{}
    curr := head
    carry := 0

    for l1 != nil || l2 != nil || carry != 0{
        num := carry
        if l1 != nil {
            num += l1.Val
            l1 = l1.Next
        }
        if l2 != nil {
            num += l2.Val
            l2 = l2.Next
        }

        curr.Next = &ListNode{Val:num%10}
        curr = curr.Next
        
        carry = num/10
    }

    return head.Next
}
```

![result](https://600345290-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FrSK2xH3txU3tYyDsT8mQ%2Fuploads%2Fgit-blob-1d475618ead27c7d936dedcdcaebd4770fae6739%2F2.png?alt=media)

Leetcode: [link](https://leetcode.com/problems/add-two-numbers/description)
