突然想不清楚了啊,那个链表翻转问题,为什么要这么写
就是迭代的那种方式
1条回答 默认 最新
关注struct ListNode* reverseList(struct ListNode *l) { struct ListNode *pre = l, *now = l->next; struct ListNode *head = l; while(now) { pre->next = now->next; // (1) 将 now 从链表中剥离出来; now->next = head; // (2) 将 now 插入到之前的链表头之前; head = now; // (3) 让 now 成为新的链表头; now = pre->next; // (4) now 也前进一格; } return head; }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用