zoukankan      html  css  js  c++  java
  • 翻转名单

    翻转列表前完成。在这里,看到一个更简单的实现

    ListNode* Reverse(ListNode *head) {
        ListNode *reHead = NULL;
        ListNode *prev = NULL;
        ListNode *Node = head;
        while(Node != NULL) {
            ListNode *next = Node->next;
            if(next == NULL)
              reHead = Node;
            Node->next = prev;
            prev = Node;
            Node = next;
        }
       return reHead;
     }

    还有

        ListNode* reverse(ListNode *head){
            if(head == NULL || head->next == NULL )
                return head;
            ListNode* tmp = reverse(head->next);
            head->next->next = head;
            head->next = NULL;
            return tmp;
        }



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    leetcode931
    leetcode1289
    leetcode1286
    poj Meteor Shower
    noip杂题题解
    noip2007部分题
    NOIP Mayan游戏
    某模拟题题解
    codevs 1423 骑士
    noip 邮票面值设计
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4799062.html
Copyright © 2011-2022 走看看