gives you two non-empty linked lists representing two non-negative integers. They are stored in reverse order per digit, and each node can only store one digit.

You can assume that neither number starts with 0 except for the number 0.
Example 1:

Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [7,0,8]
Explanation: 342 + 465 = 807.
Example 2:

Input: l1 = [0], l2 = [0]
output: [0]
Example 3:

Input: l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
Output: [8,9,9,9,0,0,0,1]

hint:

The number of nodes in each linked list is in the range [1, 100]
0 <= Node.val <= 9
The title data ensures that the numbers represented by the list do not contain leading zeros

Source: LeetCode

## code

(recursive)

```/**
* 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:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
if(l1==nullptr)
return l2;
if(l2==nullptr)
return l1;
int sum=l1->val+l2->val;
if(sum>9)
else
}
};
```

recursion 2

```class Solution {
public:
ListNode* addNumbers(ListNode* l1, ListNode* l2,int res) {
if(l1==nullptr&&l2==nullptr&&res==0)
return nullptr;
ListNode* child=new ListNode();
int value=0;
if(l1!=nullptr){
value+=l1->val;
}
if(l2!=nullptr){
value+=l2->val;
}
value+=res;
child->val=value%10;
value=value/10;
return child;
}
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
}
};

```

non-recursive

```/**
* 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:
ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
if(l1==nullptr)
return l2;
if(l2==nullptr)
return l1;
int jinwei=0,num=0;
while(l1&&l2){
num=(l1->val+l2->val+jinwei)%10;
jinwei=(l1->val+l2->val+jinwei)/10;
ListNode *temp=new ListNode(num);
cur->next=temp;
cur=temp;
l1=l1->next;
l2=l2->next;
}
while(l1){
num=(l1->val+jinwei)%10;
jinwei=(l1->val+jinwei)/10;
ListNode *temp=new ListNode(num);
cur->next=temp;
cur=temp;
l1=l1->next;
}
while(l2){
num=(l2->val+jinwei)%10;
jinwei=(l2->val+jinwei)/10;
ListNode *temp=new ListNode(num);
cur->next=temp;
cur=temp;
l2=l2->next;
}
if(jinwei){
cur->next=new ListNode(1);
}
}
};
```

## Title (pow(x, n))

Implements pow(x, n) , a function that computes x raised to the nth power of an integer (ie, xn ).

Example 1:

Input: x = 2.00000, n = 10
Output: 1024.00000
Example 2:

Input: x = 2.10000, n = 3
output: 9.26100
Example 3:

Input: x = 2.00000, n = -2
output: 0.25000
Explanation: 2-2 = 1/22 = 1/4 = 0.25

hint:

-100.0 < x < 100.0
-231 <= n <= 231-1
-104 <= xn <= 104

Source: LeetCode
I wrote it myself, and it times out when the number is extremely large~

```class Solution {
public:
double myPow(double x, int n) {
if(n==1)
return x;
else if(n==-1)
return 1/x;
else if(n<-1)
return 1/x*myPow(x,n+1);
else
return x*myPow(x,n-1);
}
};
```

Reference code~

```class Solution {
public:
double myPow(double x, int n) {
if (n == 0) {
return 1.0;
} else if ((n & 1) == 0) {
return myPow(x * x, n / 2);
} else {
return (n > 0 ? x : 1.0 / x) * myPow(x * x, n / 2);
}
}
};
```

L0 → L1 → ... → Ln - 1 → Ln

L0 → Ln → L1 → Ln - 1 → L2 → Ln - 2 → ...
You can't just change the value inside the node, but actually need to exchange the node.

Example 1:

Output: [1,4,2,3]
Example 2:

Output: [1,5,2,4,3]

hint:

The length of the linked list is in the range [1, 5 * 104]
1 <= node.val <= 1000

Source: LeetCode

## code

```/**
* 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:
return ;
ListNode *pre=new ListNode();
while(temp->next){
pre=temp;
temp=temp->next;
}