题解 | #反转链表#

反转链表

https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca

struct ListNode* ReverseList(struct ListNode* pHead ) {
    // write code here
    if (pHead == NULL) {
        return NULL;
    }
    struct ListNode* ptmp;
    struct ListNode* pNh = (struct ListNode*)malloc(sizeof(struct ListNode));
    pNh->next = NULL;
    while (pHead != NULL) {
        ptmp = (struct ListNode*)malloc(sizeof(struct ListNode));
        ptmp->val = pHead->val;
        ptmp->next = pNh->next;
        pNh->next = ptmp;
        pHead = pHead->next;
    }
    struct ListNode* pResult = pNh->next;
    return pResult;

}

全部评论

相关推荐

这就是伊泽瑞尔:进什么厂,就是三方面决定,八股+项目可以进中小厂,要进大厂再刷刷算法。
点赞 评论 收藏
分享
一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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