Skip to content

Commit 4b93ed6

Browse files
authored
Merge pull request #275 from Kavisha20340/master
Added solution to Leetcode Problem #206
2 parents 3384a0d + bb3dc64 commit 4b93ed6

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

leetcode/cpp/linkedlist/206.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)