/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* sortCowsIV(ListNode* head) {
// write code here
ListNode* t_0 = new ListNode(-1);
ListNode* t_1 = new ListNode(-1);
ListNode* pre_t_0 = t_0;
ListNode* pre_t_1 = t_1;
ListNode* t = head;
while(t)
{
if(t->val==0)
{
t_0->next = new ListNode(0);
t_0 = t_0->next;
}
else
{
t_1->next = new ListNode(1);
t_1 = t_1->next;
}
t = t->next;
}
t_0->next = pre_t_1->next;
return pre_t_0->next;
}
};