[LeetCode]002.Add Two Numbers

Question

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

Solution

  • C
1
2
3
4
5
6
7
8
9
10
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
}
  • C++
1
2
3
4
5
6
class Solution {
public:
vector<int> twoSum(vector<int> &numbers, int target) {
}
};
  • Java
1
2
3
4
5
public class Solution {
public int[] twoSum(int[] nums, int target) {
}
}
  • JavaScript
1
2
3
4
5
6
7
8
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
};
  • Python
1
2
3
4
5
class Solution:
# @param {integer[]} nums
# @param {integer} target
# @return {integer[]}
def twoSum(self, nums, target):
  • Swift
1
Hello World
坚持原创技术分享,您的支持将鼓励我继续创作!