We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def insert(self,head,data):
temp = Node(data)
if head is None:
head = temp
return head
current = head
while current.next is not None:
current = current.next
current.next = temp
return head
Problem solution in java programming.
public static Node insert(Node head,int data){
// if list has no elements, return a new node
if(head == null){
return new Node(data);
}
// else iterate through list, add node to tail, and return head
Node tmp = head;
while(tmp.next != null){
tmp = tmp.next;
}
tmp.next = new Node(data);
return head;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating phone numbers
You are viewing a single comment's thread. Return to all comments →
def insert(self,head,data): temp = Node(data) if head is None: head = temp return head current = head while current.next is not None: current = current.next current.next = temp return head
Problem solution in java programming. public static Node insert(Node head,int data){ // if list has no elements, return a new node if(head == null){ return new Node(data); }