题解 | #反转链表#
反转链表
https://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca
struct ListNode* ReverseList(struct ListNode* pHead ) { // write code here if (pHead == NULL) { return NULL; } struct ListNode* ptmp; struct ListNode* pNh = (struct ListNode*)malloc(sizeof(struct ListNode)); pNh->next = NULL; while (pHead != NULL) { ptmp = (struct ListNode*)malloc(sizeof(struct ListNode)); ptmp->val = pHead->val; ptmp->next = pNh->next; pNh->next = ptmp; pHead = pHead->next; } struct ListNode* pResult = pNh->next; return pResult; }