当前位置: 移动技术网 > IT编程>脚本编程>Python > leetcode 2. Add Two Numbers

leetcode 2. Add Two Numbers

2018年12月26日  | 移动技术网IT编程  | 我要评论
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)

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网