-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Link Lists - print reverse order
- Loading branch information
Edward Louie
committed
Oct 27, 2020
1 parent
be96654
commit edfed07
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* A LinkedList based solution for Printing a List in reverse | ||
*/ | ||
|
||
function main () { | ||
/* | ||
Problem Statement: | ||
Given a linked list, print the nodes in reverse order. | ||
Link for the Problem: https://leetcode.com/problems/reverse-linked-list/ | ||
*/ | ||
|
||
let head = '' | ||
reverseList(head) | ||
} | ||
|
||
reverseList = function (headNode) { | ||
let currentNode = headNode | ||
if (currentNode != null) { | ||
reverseList(currentNode.next) | ||
console.log(currentNode) | ||
} | ||
} | ||
|
||
main() | ||
|