cpp solution linkedlist
slow and fast pointer\n\n\n\tclass Solution {\n\tpublic:\n\t\tListNode mergeNodes(ListNode head) {\n\t\t\tListNode slow = nullptr;\n\t\t\tListNode fast = head;\
slow and fast pointer\n\n\n\tclass Solution {\n\tpublic:\n\t\tListNode* mergeNodes(ListNode* head) {\n\t\t\tListNode *slow = nullptr;\n\t\t\tListNode *fast = head;\n\t\t\tListNode *newHead = nullptr;\n\t\t\twhile(fast and fast->next){\n\t\t\t\tif(fast->val == 0){\n\t\t\t\t\tfast = fast->next;\n\n\t\t\t\t\t// change the slow->next = fast;\n\t\t\t\t\tif(newHead==nullptr){\n\t\t\t\t\t\tnewHead = fast;\n\t\t\t\t\t\tslow = fast;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tslow->next = fast;\n\t\t\t\t\tslow = slow->next;\n\t\t\t\t}\n\n\n\t\t\t\tfast = fast->next;\n\t\t\t\tslow->val += fast->val;\n\n\t\t\t}\n\t\t\tif(fast->val==0){\n\t\t\t\tslow->next = nullptr;\n\t\t\t}\n\t\t\treturn newHead;\n\t\t}\n\t};
['Linked List']