/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
typedef struct ListNode LNode ;
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
LNode *thisNode = pHead;
LNode *priorNode = NULL;
while(thisNode) {
LNode *tempNode = thisNode->next;
thisNode->next = priorNode;
priorNode = thisNode;
thisNode = tempNode;
}
return priorNode;
}
两张解法:
双指针和递归法。
以上是双指针的代码。

京公网安备 11010502036488号