写个算法还要各种查python语法…真可怜(⊙﹏⊙)b

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.

Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)

Output: 7 -> 0 -> 8

从左到右相加即可,注意进位的情况。

https://leetcode-cn.com/problems/add-two-numbers/

 

Python版本:

新手python提示: 这里的与是 and ,不是 && …心疼(⊙﹏⊙)b

 

C++版本

 

GO 版本1:

 

Go版本2:另外发现还可以递归来实现,代码短,但是耗费栈空间

 

自行评判吧

【LeetCode】2. Add Two Numbers
Tagged on: