Top101题解 | BM1#反转链表#
反转链表
https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=295&tqId=23286&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj
代码:
/** * struct ListNode { * int val; * struct ListNode *next; * }; */ /** * @author Senky * @date 2023.03.17 * @par url https://www.nowcoder.com/creation/manager/content/584337070?type=column&status=-1 * @param pHead ListNode类 * @return ListNode类 */ struct ListNode* ReverseList(struct ListNode* pHead ) { // write code here struct ListNode* prev = NULL; struct ListNode* curr = pHead; struct ListNode* next; //退出循环后curr指向NULL while(curr != NULL) { next = curr->next; curr->next = prev; prev = curr; curr = next; } return prev; }
图解:
TOP101-BM系列 文章被收录于专栏
系列的题解