Why runtime err?


  • 0
    Y
     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) {
            if(head == NULL) return head;
            ListNode* headt = head;
            stack<int> temp;
            while(headt != NULL){
                temp.push(headt -> val);
                headt = headt -> next;
            }
            headt = head -> next;
            while(temp.size()){
                headt -> val = temp.top();
                headt = headt -> next;
                temp.pop();
            }
            return head;
        }
    };

Log in to reply
 

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