C++ using pointer pre and next


  • 0
    W
    class Solution {
    public:
        ListNode* reverseList(ListNode* head) {
            ListNode *pre, *next;
    		ListNode *it = head;
    		pre = NULL;
    		while(it){
    			next = it->next;
    			it->next = pre;
    			pre = it;
    			it = next;
    		}
    		return pre;
        }
    };

Log in to reply
 

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