It is very easy to come up with a brute force soulution which Time complex is O(n ^ 2).However, we can use a map structure to record the num and index in the nums we have iteratered. And also, when we check each number, we can find (target - number) in the current map. Then, it will be the solution.
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.
This problem is quite similar to merge sort. Hence, in my case, I use the concept the merge sort to generate a new line. In addition, when we calculate the last number, we shuould determine whether it has a carry. In my case, I use a variable called flag to record the carry.
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.
This problem is quite similar to merge sort. Hence, in my case, I use the concept the merge sort to generate a new line. In addition, when we calculate the last number, we shuould determine whether it has a carry. In my case, I use a variable called flag to record the carry.