leetcode/include/s2_add_two_numbers.hpp
2022-03-10 20:25:55 +08:00

32 lines
836 B
C++

#ifndef S2_ADD_TWO_NUMBERS_HPP
#define S2_ADD_TWO_NUMBERS_HPP
struct ListNode {
int val;
ListNode* next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode* next) : val(x), next(next) {}
};
class Solution {
public:
/**
* @brief Add Two Numbers
*
* 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 contains a single digit. Add the two numbers and return the sum as a
* linked list.
*
* You may assume the two numbers do not contain any leading zero, except the
* number 0 itself.
*
* @param l1 the first linked list
* @param l2 the second linked list
*/
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2);
};
#endif