2. Add Two Numbers
You are given two linked lists representing two non - negative numbers.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.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output : 7 -> 0 -> 8
题意:
有两个链表作为输入,它们表示逆序的两个非负数。如下面的两个链表表示的是342和465这两个数。你需要计算它们的和并且用同样的方式逆序输出。如342 + 465 = 807, 你需要把结果表达为7 ->0 ->8
输入: (2 -> 4 -> 3) + (5 -> 6 -> 4)
输出:Output : 7 -> 0 -> 8
思路:
1 | ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { |
Java Code:
1 | /** |