Skip to content

Commit 5d5349b

Browse files
authored
Create 1265-print-immutable-linked-list-in-reverse.js
1 parent f66ef84 commit 5d5349b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* // This is the ImmutableListNode's API interface.
3+
* // You should not implement it, or speculate about its implementation.
4+
* function ImmutableListNode() {
5+
* @ return {void}
6+
* this.printValue = function() { // print the value of this node.
7+
* ...
8+
* };
9+
*
10+
* @return {ImmutableListNode}
11+
* this.getNext = function() { // return the next node.
12+
* ...
13+
* };
14+
* };
15+
*/
16+
17+
/**
18+
* @param {ImmutableListNode} head
19+
* @return {void}
20+
*/
21+
var printLinkedListInReverse = function(head) {
22+
dfs(head)
23+
function dfs(node) {
24+
if(node.getNext() == null) {
25+
node.printValue()
26+
return
27+
}
28+
dfs(node.getNext())
29+
node.printValue()
30+
}
31+
};

0 commit comments

Comments
 (0)