-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1265-PrintImmutableLinkedListInReverse.cs
52 lines (44 loc) · 1.46 KB
/
1265-PrintImmutableLinkedListInReverse.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//-----------------------------------------------------------------------------
// Runtime: 232MS
// Memory Usage: 30.1 MB
// Link: https://leetcode.com/submissions/detail/359629468/
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace LeetCode
{
/**
* // This is the ImmutableListNode's API interface.
* // You should not implement it, or speculate about its implementation.
* class ImmutableListNode {
* public void PrintValue(); // print the value of this node.
* public ImmutableListNode GetNext(); // return the next node.
* }
*/
public class _1265_PrintImmutableLinkedListInReverse
{
public void PrintLinkedListInReverse(ImmutableListNode head)
{
if (head == null) return;
PrintLinkedListInReverse(head.GetNext());
head.PrintValue();
}
public class ImmutableListNode : ListNode
{
private readonly IList<int> list;
public ImmutableListNode(IList<int> list, int value, ImmutableListNode next)
: base(value)
{
this.list = list;
this.next = next;
}
public void PrintValue()
{
list.Add(val);
}
public ImmutableListNode GetNext()
{
return (ImmutableListNode)next;
}
}
}
}