2、Add Two Numbers

来源:互联网 发布:淘宝售后换货申请 编辑:程序博客网 时间:2024/05/22 20:35

题目内容:

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

题目分析:

该题主要考察链表的思想,以及加法的思想实现,注意建造新的链表时将节点付给链表结点的next当中而不是直接付给链表中的本节点,否则链表的节点无法连接,还要注意的事如果最高位还要进位的话还需要再增加一个节点位。

题目代码:

原创粉丝点击