遍历链表出错
节点结构:
/** * 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; } //当前节点指向下一个节点 //前面一直写的pHead++,导致指针出错 pHead = nextNode; }