Skip to content

Commit feadd82

Browse files
committed
Reverse Linked List solution
1 parent e6c4510 commit feadd82

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

reverse-linked-list/PDKhan.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
ListNode* reverseList(ListNode* head) {
4+
ListNode* new_head = NULL;
5+
6+
while(head){
7+
ListNode* next = head->next;
8+
9+
head->next = new_head;
10+
new_head = head;
11+
head = next;
12+
}
13+
14+
return new_head;
15+
}
16+
};

0 commit comments

Comments
 (0)