C语音代码如下:
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
struct ListNode * node = NULL;
struct ListNode * tmpHead = pHead;
struct ListNode * head = NULL;
while (tmpHead) {
node = tmpHead;
tmpHead = tmpHead->next;
node->next = head;
head = node;
}
return head;
}
运行结果: