• + 0 comments

    Java Solution:

    class Solution {
    
        public static  Node insert(Node head,int data) {
            //Complete this method
            Node newNode = new Node(data);
            newNode.next = null;
            
            if(head == null){
                return head = newNode;
            }
            
            Node curr = head;
            while(curr.next != null){
                curr = curr.next;
            }
            curr.next = newNode;
            return head;
        }