C++ solution .. very easy..


  • 10
    H
    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     ListNode *next;
     *     ListNode(int x) : val(x), next(NULL) {}
     * };
     */
    class Solution {
    public:
        ListNode* reverseList(ListNode* head) {
            ListNode *temp = NULL , *nextNode = NULL;
            while(head){
                nextNode = head->next;
                head->next = temp;
                temp = head;
                head = nextNode;
            }
            return temp;
        }
    };

  • 0
    T

    so smart~~~~~


  • 0
    T
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.