Skip to content

Commit

Permalink
Added solution to larissalages#206
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavisha20340 committed Oct 19, 2020
1 parent 5a44fe7 commit bb3dc64
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions leetcode/cpp/linkedlist/206.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Leetcode Problem #206
// Title : Reverse Linked list
/**
* 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=head,*q=NULL,*r=NULL;
while(p!=NULL)
{
r=q;
q=p;
p=p->next;
q->next=r;
}
head=q;
return head;
}
};

0 comments on commit bb3dc64

Please sign in to comment.