2 Star 0 Fork 0

xinanXu/myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LC143.cpp 549 Bytes
一键复制 编辑 原始数据 按行查看 历史
xinanXu 提交于 2023-02-07 00:48 . 143 重排链表
class Solution {
public:
void reorderList(ListNode* head) {
vector<ListNode*> arr;
ListNode* p = head;
while (p != nullptr) {
arr.push_back(p);
p = p->next;
}
int tail = arr.size() - 1;
p = head;
for (int i = 0; i < (arr.size() - 1) / 2; i++) {
ListNode* t = p->next;
arr[tail]->next = t;
p->next = arr[tail];
tail -= 1;
arr[tail]->next = nullptr;
p = t;
}
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/DearAtri/myleetcode.git
git@gitee.com:DearAtri/myleetcode.git
DearAtri
myleetcode
myleetcode
master

搜索帮助