/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
#include <vector>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* sortCowsIV(ListNode* head) {
vector<ListNode*> black;
vector<ListNode*> white;
ListNode* p = head;
while(p){
if(p->val == 0){
black.emplace_back(p);
}else{
white.emplace_back(p);
}
p = p->next;
}
ListNode* new_head = new ListNode(0);
p = new_head;
for(int i = 0; i < black.size(); i++){
p->next = black[i];
p = p->next;
cout << p->val;
}
cout << endl;
for(int i = 0; i < white.size(); i++){
p->next = white[i];
p = p->next;
cout << p->val;
}
p->next = nullptr;
return new_head->next;
}
};