赞
踩
class Solution
{
public:
ListNode* reverseList(ListNode* head)
{
if (head == NULL)
{
return NULL;
}
ListNode *previousNode = NULL;
ListNode *currentNode = head;
ListNode *nextNode = head->next;
while (nextNode != NULL)
{
currentNode->next = previousNode;
previousNode = currentNode;
currentNode = nextNode;
nextNode = currentNode->next;
}
currentNode->next = previousNode;
return currentNode;
}
};
class Solution
{
public:
ListNode* reverseList(ListNode* head)
{
if (head == NULL || head->next == NULL)
{
return head;
}
ListNode *p = reverseList(head->next);
head->next->next = head;
head->next = NULL;
return p;
}
};
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。