File tree Expand file tree Collapse file tree 1 file changed +16
-21
lines changed
Linked_List/430.Flatten-a-Multilevel-Doubly-Linked-List Expand file tree Collapse file tree 1 file changed +16
-21
lines changed Original file line number Diff line number Diff line change @@ -25,33 +25,28 @@ class Solution {
25
25
Node* child = h->child ;
26
26
h->child = NULL ;
27
27
28
- if (child == NULL )
28
+ if (child==NULL && next==NULL )
29
+ return h;
30
+ else if (child!=NULL && next==NULL )
29
31
{
30
- h->next = next;
31
- if (next == NULL )
32
- return h;
33
- else
34
- {
35
- next->prev = h;
36
- return findEnd (next);
37
- }
32
+ h->next = child;
33
+ child->prev = h;
34
+ Node* childEnd = findEnd (child);
35
+ return childEnd;
36
+ }
37
+ else if (child==NULL && next!=NULL )
38
+ {
39
+ Node* nextEnd = findEnd (next);
40
+ return nextEnd;
38
41
}
39
42
else
40
43
{
41
44
h->next = child;
42
45
child->prev = h;
43
- Node* childEnd = findEnd (child);
44
- if (next==NULL )
45
- {
46
- childEnd->next = NULL ;
47
- return childEnd;
48
- }
49
- else
50
- {
51
- childEnd->next = next;
52
- next->prev = childEnd;
53
- return findEnd (next);
54
- }
46
+ Node* childEnd = findEnd (child);
47
+ childEnd->next = next;
48
+ next->prev = childEnd;
49
+ return findEnd (next);
55
50
}
56
51
}
57
52
};
You can’t perform that action at this time.
0 commit comments