[Leetcode] to delete the list of nodes

Traverse the list errors

Node structure:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
while(pHead->next!=nullptr)
        {
            ListNode* nextNode = pHead->next;
            if(nextNode->val == val)
            {
                break;
            }
            // current node points to the next node
             // front has been written pHead ++, resulting in an error pointer 
            PHEAD = nextNode;  
        }

 

Guess you like

Origin www.cnblogs.com/hopping/p/12297421.html