Node Swap Time : O(n) Space : O(1) 1234567891011121314151617181920212223242526272829using namespace std;// This is an input struct. Do not edit.class LinkedList {public: int value; LinkedList *next = nullptr; LinkedList(int value) { this->value = value; }};LinkedList *nodeSwap(LinkedList *head) { if(head == nullptr) return nullptr; LinkedList *dummy = new LinkedList(-1); dummy->next = head; LinkedList *prv = dummy, *now = head, *nxt; while(now) { if(now->next == nullptr) break; nxt = now->next; LinkedList* tmp = nxt->next; prv->next = nxt; nxt->next = now; now->next = tmp; prv = now; now = tmp; } return dummy->next;}