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) |
|
|
|
|
|
} |
|
class Solution { public: ListNode addTwoNumbers(ListNode l1, ListNode *l2) {
}; |
/ * Definition for singly-linked list. * struct ListNode { * int val; * ListNode next; * ListNode(int x) : val(x), next(NULL) {} * }; / class Solution { public: void ReverseLL(ListNode headNode) { ListNode prev = NULL; ListNode temp1 = headNode; ListNode temp2 = headNode->next;
}; |
package LinkedListStuff; class Node { int data; Node link;
} public class AddTwoNumbers { public Node AddTwoNumbers(Node num1, Node num2) { if (num1 == null) return num2; else if (num2 == null) return num1;
} |