leetcode/include/s0002_add_two_numbers.hpp

32 lines
842 B
C++
Raw Normal View History

2022-03-12 03:04:49 +00:00
#ifndef S0002_ADD_TWO_NUMBERS_HPP
#define S0002_ADD_TWO_NUMBERS_HPP
2022-03-10 12:25:55 +00:00
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