代码拉取完成,页面将自动刷新
//
// Created by 旺崽 on 2021/10/31.
//
#include "bits/stdc++.h"
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode() : val(0), next(nullptr) {}
ListNode(int x) : val(x), next(nullptr) {}
ListNode(int x, ListNode *next) : val(x), next(next) {}
};
class Solution {
public:
ListNode *middleNode(ListNode *head) {
ListNode *slow = head, *fast = head;
while (fast->next != nullptr) {
slow = slow->next;
fast = fast->next;
if (fast->next != nullptr) fast = fast->next;
}
return slow;
}
ListNode *reverseList(ListNode *head) {
ListNode *pre = nullptr;
ListNode *cur = head;
while (cur) {
ListNode *next = cur->next;
cur->next = pre;
pre = cur;
cur = next;
}
return pre;
}
void reorderList(ListNode *head) {
ListNode *start = head;
head = middleNode(head);
ListNode *tail = head->next;
head->next = nullptr;//封尾
head = start;
ListNode *ans = head;
tail = reverseList(tail);
while (tail != nullptr) {
ListNode *c = head->next;
ListNode *d = tail->next;
head->next = tail;
tail->next = c;
head = c;
tail = d;
}
head = ans;
}
};
int main() {
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。