Leetcode 2

作者: SiweiWang | 来源:发表于2017-12-05 12:41 被阅读0次

原题

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

    本文链接:https://www.haomeiwen.com/subject/zeoqixtx.html