题目链接
思路
双指针
class Solution {
public:
void reorderList(ListNode
* head
) {
vector
<ListNode
*> v
;
ListNode
* tmp
= head
;
while (tmp
) {
v
.push_back(tmp
);
tmp
= tmp
->next
;
}
int l
= 0, r
= v
.size() - 1;
while (l
< r
-1) {
v
[l
]->next
= v
[r
];
v
[r
]->next
= v
[l
+1];
v
[r
-1]->next
= nullptr;
l
++; r
--;
}
}
};
转载请注明原文地址: https://lol.8miu.com/read-100.html