leetcode 2. Add Two Numbers

2018-12-27 07:43:06来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

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)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:python输出mssql 查询结果示例

下一篇:字符串的操作方法(第二天)