###### tags: `LeetCode` `Linked List` `Easy` # LeetCode #206 [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/) ### (Easy) 給你單向鏈結串列的頭節點 head ,請你反轉鏈結串列,並返回反轉後的鏈結串列。 ![](https://i.imgur.com/k4Lu0jd.png) --- ``` /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ListNode(int x, ListNode *next) : val(x), next(next) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* head) { ListNode *p=nullptr, *n=nullptr; while(head){ n = head->next; head->next=p; p=head; head=n; } return p; } }; ```