题解 | #从尾到头打印链表#

从尾到头打印链表

https://www.nowcoder.com/practice/d0267f7f55b3412ba93bd35cfa8e8035

int* printListFromTailToHead(struct ListNode* listNode, int* returnSize ) {
    // write code here
        struct ListNode* p=listNode;
        int count=0;
        while(p!=NULL){
            count++;
            p=p->next;
        }
        int a[count];
        int i=0;
        p=listNode;
        while(p!=NULL){
            a[i]=p->val;
            i++;
            p=p->next;
        }
        * returnSize=count;
        int *b=(int *)malloc(sizeof(int)*count);
        for(int k=0;k<count;k++){
            b[k]=a[i-1];
            i--;
        }
        return b;
}

全部评论

相关推荐

牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务