Add Two Numbers - LeetCode
Add Two Numbers - LeetCode
Python Auto
2. Add Two Numbers 1 # Definition for singly-linked list.
2 # class ListNode(object):
Medium Topics Companies 3 # def __init__(self, val=0, next=None):
4 # self.val = val
You are given two non-empty linked lists representing two non-negative integers. The 5 # self.next = next
digits are stored in reverse order, and each of their nodes contains a single digit. Add 6 class Solution(object):
the two numbers and return the sum as a linked list. 7 def addTwoNumbers(self, l1, l2):
8 """
You may assume the two numbers do not contain any leading zero, except the number 0 9 :type l1: Optional[ListNode]
10 :type l2: Optional[ListNode]
itself.
11 :rtype: Optional[ListNode]
12 """
13
Example 1:
Saved