-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path35.h
More file actions
34 lines (32 loc) · 630 Bytes
/
35.h
File metadata and controls
34 lines (32 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Definition of ListNode
*
* class ListNode {
* public:
* int val;
* ListNode *next;
*
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
public:
/*
* @param head: n
* @return: The new head of reversed linked list.
*/
ListNode * reverse(ListNode * head) {
// write your code here
ListNode *prev = nullptr;
while(head != nullptr){
ListNode *next = head->next;
head->next = prev;
prev = head;
head = next;
}
return prev;
}
};