Leetcode 2

原题

You are given twonon-emptylinked lists representing two non-negative integers. The digits are stored inreverse orderand 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.

这道题的思路比较直接, 从第一个数开始一直到最后一个,两两相加。几点需要主要

1. 进位

2. 不对称 -- 两个数组不一样长。举个例子 (2) + (5 -> 6 -> 4), 这个时候注意用Null 补齐



Java Code:


你可能感兴趣的:(Leetcode 2)