Why does my code give right answers when tested on my PC( but it goes wrong on this website)?

  • -1
    ListNode* reverseList(ListNode* head) {
            ListNode *p, *q, *t;
        	if (head == NULL)
        		return NULL;
        	t = head->next;
        	if (t == NULL)
        		return head;
        	p = t;
        	p = p->next;
        	while (t->next != NULL)
    	    	t->next = p->next;
    	    	q = p;
    	    	p = p->next;
    	    	q->next = head->next;
    	    	head->next = q;
    	    return head;

  • 0

    Well, now I know the reason. The given head is actually not a head point , but the first point in the linked list.

  • 1

    @perfectizer New users please read the instructions to format your code properly.

Log in to reply

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