还不快抢沙发

添加新评论

反转一个单链表。 例如: 输入`[6,7,8]` 输出`[8,7,6]` ``` ListNode* reverseList(ListNode* head) { if (!head) return nullptr; vector collection; ListNode* out = nullptr; while (head) { collection.push_back(head); head = head->next; } auto iter = collection.begin(); do { auto prev = new ListNode((*iter)->val); prev->next = out; out = prev; iter++; } while (iter != collection.end()); return out; } ```