leetcode 2. Add Two Numbers
程序员文章站
2022-11-08 21:41:16
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)
上一篇: 海南适合情侣游玩的地方大全
下一篇: 西安最不值得去的景点大全 去了就觉得坑