题目描述

输入一个链表,反转链表后,输出链表的所有元素。
/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
        ListNode* head = pHead;
        ListNode* p1 = pHead;
        ListNode* p2 = pHead;
        head = NULL;
        while(p1){
            p2 = p1->next;
            p1->next = head;
            head = p1;
            p1=p2;
        }
        return head;
    }
};

  

相关文章:

  • 2022-01-11
  • 2021-07-01
  • 2021-08-26
  • 2021-12-12
  • 2021-11-26
  • 2021-11-05
  • 2021-08-29
  • 2021-07-23
猜你喜欢
  • 2021-12-10
  • 2021-12-15
  • 2021-08-23
  • 2021-07-12
  • 2021-09-26
  • 2021-12-02
  • 2021-08-19
相关资源
相似解决方案