k****r 发帖数: 807 | 1 我是这样写的,但是不能通过,
ListNode *insertionSortList(ListNode *head) {
// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
if (head == NULL || head->next == NULL) return head;
ListNode dummyHead(INT_MIN);
(&dummyHead)->next = head;
ListNode *cur = head->next;
while (cur) {
ListNode *pre = &dummyHead;
while(pre->next && pre->next->val < cur->val) pre = pre->next;
ListNode *tmp = cur->next;
cur->next = pre->next;
pre->next = cur;
cur = tmp;
}
return dummyHead.next;
}
得到Time Limit Exceeded {1,1}的错误。我实在看不出我写的哪里有问题了。。。。
包子求问!谢谢啦 | c*******2 发帖数: 60 | 2
这里加个 head->next = null;
【在 k****r 的大作中提到】 : 我是这样写的,但是不能通过, : ListNode *insertionSortList(ListNode *head) { : // IMPORTANT: Please reset any member data you declared, as : // the same Solution instance will be reused for each test case. : if (head == NULL || head->next == NULL) return head; : ListNode dummyHead(INT_MIN); : (&dummyHead)->next = head; : ListNode *cur = head->next; : while (cur) { : ListNode *pre = &dummyHead;
| k****r 发帖数: 807 | |
|