zoukankan      html  css  js  c++  java
  • 30 Day Challenge Day 6 | Leetcode 206. Reverse Linked List

    题解

    很基础的题,与reverseDoublyLinkedList(Hackerrank)那道题作对照,实际上只有一样代码的差别。

    class Solution {
    public:
        ListNode* reverseList(ListNode* head) {
            if(!head || !head->next) return head;
    
            ListNode* prev = nullptr;
            ListNode* curr = head;
    
            while(curr) {
                ListNode* temp = curr->next;
                curr->next = prev;
                prev = curr;
                curr = temp;
            }
    
            return prev;
        }
    };
    
  • 相关阅读:
    NYOJ 734
    NYOJ 762
    NYOJ 743
    NYOJ 478
    NYOJ 451
    NYOJ 461
    NYOJ 485
    NYOJ 333
    平均互信息
    ASCII码
  • 原文地址:https://www.cnblogs.com/casperwin/p/13636754.html
Copyright © 2011-2022 走看看