力扣第二题
记录一下错误原因。虽然错误描述看不懂,但原因是自己的指针指向了自己。
heap堆
heap-use-after-free on address 释放地址后使用堆。
/**
* Definition for singly-linked list.
* 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) {
ListNode* tail; //执行指针
ListNode* tou=new ListNode();//头指针
tou->next=nullptr;
tail=tou;
int next=0; //产生的进位
while(l1||l2){
int sum=0;
if(l1!=NULL){
sum+=l1->val;
l1=l1->next;
}
if(l2!=NULL){
sum+=l2