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:


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 上通信的课就跟室友一起刷题玩,结果读题目读了半天,好歹我也是过了四级的人啊,怎么能这样,干脆百度题目意思…… 题目...
    做梦枯岛醒阅读 245评论 0 0
  • You are given two non-empty linked lists representing two...
    MarkTang阅读 432评论 0 0
  • You are given two linked lists representing two non-negat...
    水月心刀阅读 145评论 0 0
  • 题目出处 来自于leetcode 题目描述 You are given two linked lists repr...
    yarving阅读 456评论 0 2
  • 花草凄凌夜,闻声秋已来。 入梦三分境,姿艳卸妆前。 素素依回眸,霜起瑟风行。 晨起运收粮,夜墨研自乐。 深秋虽硕累...
    泽焉阅读 199评论 0 0