Skip to content

Instantly share code, notes, and snippets.

@Preetiraj3697
Forked from rahul4coding/insertNodeAtTail.js
Created October 21, 2022 05:51
Show Gist options
  • Save Preetiraj3697/b94ab6cec11e9ef43430898183bf17b4 to your computer and use it in GitHub Desktop.
Save Preetiraj3697/b94ab6cec11e9ef43430898183bf17b4 to your computer and use it in GitHub Desktop.
Insert node at a tail of Linked List | HAckerRank
// 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