LeetCode第2题:Add Two Numbers总结

题目

You are given two linked lists representing two non-negative numbers. 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.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8

大意:给出两个从低位到高位排列链表形式的多位数,相加后按原格式输出。

分析

感觉这道题还是比较简单的,除了有的语法有点不熟悉查了下书以外,还都是挺顺利的。
编写时,只要注意进位的判断和退出的条件就可以了,代码如下:

Python

C++

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注