小编Jov*_*vić的帖子

Leetcode 中等问题(单链表)

1561/1563 个测试用例通过

问题描述:

给您两个表示两个非负整数的非空链表。最高有效数字在前,每个节点都包含一个数字。将两个数字相加并以链表形式返回总和。

您可以假设这两个数字不包含任何前导零,除了数字 0 本身。问题链接: https: //leetcode.com/problems/add-two-numbers-ii/

您不需要向我提供代码(会有帮助),只需提供为什么我在接下来的问题中得到错误答案的答案。

void insert_begging(struct ListNode **root,unsigned __int128 val){
    struct ListNode *new_node = malloc(sizeof(struct ListNode));
    new_node->val = val;
    if(*root == NULL){
        new_node->next = NULL;
        *root = new_node;
        return;
    }
    new_node->next = *root;
    *root = new_node;
}
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2){
    struct ListNode* result = NULL;
    struct ListNode* curr = l1;
    unsigned __int128  sum = 0;
    unsigned __int128 sum2 = 0;
    while(curr!=NULL){
        sum=sum*10+curr->val;
        curr=curr->next;
    }
    struct ListNode* curr2 = l2; …
Run Code Online (Sandbox Code Playgroud)

c reverse linked-list singly-linked-list function-definition

2
推荐指数
1
解决办法
114
查看次数