欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

leetcode 2. Add Two Numbers

程序员文章站 2022-05-02 16:50:19
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai ......

you are given two non-empty linked lists representing two non-negative integers. the digits are stored in reverse order and each of their nodes contain a single digit. add the two numbers and return it as a linked list.

you may assume the two numbers do not contain any leading zero, except the number 0 itself.

example:

input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
output: 7 -> 0 -> 8
explanation: 342 + 465 = 807.

 

# coding=utf-8

a=[2,4,3]
b=[5,6,4]

a.reverse()
b.reverse()
c=0
str1=""
str2=""

for i in a:
str1+=str(i)
for j in b:
str2+=str(j)
c=int(str1)+int(str2)
print(c)