Skip to content

Commit

Permalink
Merge pull request #275 from Kavisha20340/master
Browse files Browse the repository at this point in the history
Added solution to Leetcode Problem #206
  • Loading branch information
larissalages committed Oct 22, 2020
2 parents 3384a0d + bb3dc64 commit 4b93ed6
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 4b93ed6

Please sign in to comment.