Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f886839

Browse files
Day 8 Solutions
1 parent 5b8d52b commit f886839

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎Day 8/206. Reverse Linked List.cpp‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
ListNode* prevptr=NULL;
15+
ListNode* currptr=head;
16+
ListNode* nextptr;
17+
18+
while(currptr != NULL){
19+
nextptr=currptr->next;
20+
currptr->next=prevptr;
21+
22+
prevptr=currptr;
23+
currptr=nextptr;
24+
}
25+
return prevptr;
26+
}
27+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /