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.
1 parent 659b26e commit 9f0732cCopy full SHA for 9f0732c
Linked_List/206.Reverse-Linked-List/206.Reverse-Linked-List.cpp
@@ -0,0 +1,28 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * ListNode *next;
6
+ * ListNode() : val(0), next(nullptr) {}
7
+ * ListNode(int x) : val(x), next(nullptr) {}
8
+ * ListNode(int x, ListNode *next) : val(x), next(next) {}
9
+ * };
10
+ */
11
+class Solution {
12
+public:
13
+ ListNode* reverseList(ListNode* head)
14
+ {
15
+ ListNode* last = NULL;
16
+ ListNode* cur = head;
17
+ ListNode* nxt;
18
+
19
+ while (cur)
20
21
+ nxt = cur->next;
22
+ cur->next = last;
23
+ last = cur;
24
+ cur = nxt;
25
+ }
26
+ return last;
27
28
+};
0 commit comments