/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) {} };*/ #include <cstddef> class Remove { public: bool removeNode(ListNode* pNode) { // write code here if(!pNode->next){ return false; } ListNode* nextNode; nextNode = pNode->next; pNode->val = pNode->next->val; pNode->next = pNode->next->next; delete nextNode; return true; } };
将下个节点的数据域复制到当前节点,然后将指针指到下下个节点,实现删除操作