Sort by

recency

|

717 Discussions

|

  • + 0 comments

    Simple JAVA approach

    public static Node insert(Node head,int data) {

        if(head==null){
            head = new Node(data);
        }
        else{
            Node start = head;
            while(start.next != null){
            start = start.next;
        }
    
        Node newNode = new Node(data);
        start.next = newNode;
        }
        return head;
    }
    
  • + 0 comments

    I was hoping for a golang option. C++ is good enough I suppose...

    Node* insert(Node *head,int data)
          {
              //Complete this method          
              Node *dummyNode = new Node(0);
              dummyNode->next = head;
              Node *newNode = new Node(data);
              Node *current = dummyNode;
              
              while (current->next != NULL) {
                current = current->next;
              }
              current->next = newNode;
              return dummyNode->next;
          }
    
  • + 0 comments
    public static  Node insert(Node head,int data)
    	{
          
        Node newNode = new Node(data);
      
        if (head == null)
        {
            return newNode;
        }
    
        Node current = head;
        while (current.next != null)
        {
            current = current.next;
        }
    
        current.next = newNode;
         return head;
        }
    
  • + 0 comments
    public static  Node insert(Node head,int data) {
            //Complete this method
            
            Node current = head;
            if (head == null)
                head = new Node(data);
            else{
                while(current.next != null){
                    current = current.next;
                }
                    current.next = new Node(data);
            }
            return head;
        }
    
  • + 0 comments

    Why do the typescript problems never have the implementations? There's no node class