Created
January 17, 2022 08:54
-
-
Save see-why/a37d2478757e959ad771876c914ed7b0 to your computer and use it in GitHub Desktop.
HackerRank Day 15 of 30 days of code challenge
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
//https://www.hackerrank.com/challenges/30-linked-list/problem?isFullScreen=true | |
process.stdin.resume(); | |
process.stdin.setEncoding('ascii'); | |
var input_stdin = ""; | |
var input_stdin_array = ""; | |
var input_currentline = 0; | |
process.stdin.on('data', function (data) { | |
input_stdin += data; | |
}); | |
process.stdin.on('end', function () { | |
input_stdin_array = input_stdin.split("\n"); | |
main(); | |
}); | |
function readLine() { | |
return input_stdin_array[input_currentline++]; | |
} | |
function Node(data){ | |
this.data=data; | |
this.next=null; | |
} | |
function Solution(){ | |
this.insert=function(head,data){ | |
//complete this method | |
if (head == undefined) { | |
head = new Node(data); | |
} else { | |
if (head.next == undefined){ | |
head.next = new Node(data); | |
} | |
else { | |
this.insert(head.next, data); | |
} | |
} | |
return head | |
}; | |
this.display=function(head){ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment