We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 3384a0d + bb3dc64 commit 4b93ed6Copy full SHA for 4b93ed6
leetcode/cpp/linkedlist/206.cpp
@@ -0,0 +1,27 @@
1
+// Leetcode Problem #206
2
+// Title : Reverse Linked list
3
+/**
4
+ * Definition for singly-linked list.
5
+ * struct ListNode {
6
+ * int val;
7
+ * ListNode *next;
8
+ * ListNode() : val(0), next(nullptr) {}
9
+ * ListNode(int x) : val(x), next(nullptr) {}
10
+ * ListNode(int x, ListNode *next) : val(x), next(next) {}
11
+ * };
12
+ */
13
+class Solution {
14
+public:
15
+ ListNode* reverseList(ListNode* head) {
16
+ ListNode *p=head,*q=NULL,*r=NULL;
17
+ while(p!=NULL)
18
+ {
19
+ r=q;
20
+ q=p;
21
+ p=p->next;
22
+ q->next=r;
23
+ }
24
+ head=q;
25
+ return head;
26
27
+};
0 commit comments