zoukankan      html  css  js  c++  java
  • NC78 反转链表 牛客

    描述

    输入一个链表,反转链表后,输出新链表的表头。

    示例1

    输入:
    {1,2,3}
    返回值:
    {3,2,1}
    
    /*
    struct ListNode {
        int val;
        struct ListNode *next;
        ListNode(int x) :
                val(x), next(NULL) {
        }
    };*/
    class Solution {
    public:
        ListNode* ReverseList(ListNode* pHead) {
          ListNode *pre=nullptr;
          ListNode *cur=pHead;
          ListNode *nxt=nullptr;
          while(cur)
          {
              nxt=cur->next;
              cur->next=pre;
              pre=cur;
              cur=nxt;
          }
            return pre;
        }
    };
  • 相关阅读:
    多线程
    多线程
    多线程
    多线程
    Java 基础
    异常
    多线程
    多线程
    多线程
    幂等性
  • 原文地址:https://www.cnblogs.com/stepping/p/14838746.html
Copyright © 2011-2022 走看看