-
-
Save Preetiraj3697/b94ab6cec11e9ef43430898183bf17b4 to your computer and use it in GitHub Desktop.
Insert node at a tail of Linked List | HAckerRank
This file contains hidden or 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/insert-a-node-at-the-tail-of-a-linked-list/problem | |
function insertNodeAtTail(head, data) { | |
var newNode = new SinglyLinkedListNode(data); | |
if(head===null){ | |
head = newNode; | |
return head; | |
}else{ | |
var tmp = head; | |
while(tmp.next!==null){ | |
tmp = tmp.next; | |
} | |
tmp.next = newNode; | |
return head; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment