题解 | #反转链表#

反转链表

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

 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 *
 * C语言声明定义全局变量请加上static,防止重复定义
 */

/**
 * 
 * @param pHead ListNode类 
 * @return ListNode类
 */
struct ListNode* ReverseList(struct ListNode* pHead ) {
    // write code here
    if(pHead == NULL)
        return NULL;
    struct ListNode *pT = pHead;
    
    struct ListNode *Head = pHead;
    while(Head->next != NULL)
    { 
        Head = Head->next;
    }
    while(pT->next != NULL)
    { 
        while(pT->next->next != NULL)
        { 
            pT = pT->next;
        }
        pT->next->next = pT;
        pT->next = NULL;
        
        pT = pHead;
        //pT = pT->next;
        
    }
    
    return Head;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-21 17:59
点赞 评论 收藏
分享
投递拓竹科技等公司10个岗位
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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