Programming/Data Structure

[Hackerrank] InsertNodeAtHead

읽고 쓰는 개발자 2020. 12. 2. 22:31

www.hackerrank.com/challenges/insert-a-node-at-the-head-of-a-linked-list/problem

Insert a node at the head of a linked list | HackerRank

Create and insert a new node at the head of a linked list

www.hackerrank.com

package exam.complete;

//https://www.hackerrank.com/challenges/insert-a-node-at-the-head-of-a-linked-list/problem

import exam.SinglyLinkedListNode;

public class InsertNodeAtHead {

    static SinglyLinkedListNode insertNodeAtHead(SinglyLinkedListNode llist, int data) {
        SinglyLinkedListNode node = new SinglyLinkedListNode(data);
        node.next = llist;
        return node;
    }
}