我的想法是每组的个数是当前的cnt/当前的k 再向上取整
struct ListNode** splitListToParts(struct ListNode* head, int k, int* returnSize){
struct ListNode** ans=(struct ListNode**)malloc(sizeof(struct ListNode*)*k);
struct ListNode* p=head;
int cnt=0;
while(p!=NULL)
{
cnt++;
p=p->next;
}
int temp,a,tempcnt;
p=head,a=k;
for(int i=0;i<a;i++)
{
ans[i]=p;
temp=(int)ceil((double)cnt/k);
tempcnt=0;
while(tempcnt<temp&&p!=NULL)
{
tempcnt++;
if(tempcnt==temp)
{
struct ListNode* q=p;
q=p->next;
p->next=NULL;
p=q;
}
else
p=p->next;
}
cnt-=temp;
k--;
}
*returnSize=a;
return ans;
}
官方更精确些