Sort by

recency

|

827 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can have the video explanation here : https://youtu.be/EjWw69vLVYo

    SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {
        if(position == 0) return llist->next;
        SinglyLinkedListNode* curr = llist;
        while(position - 1) {
            curr = curr -> next;
            position--;
        }
        curr->next = curr->next->next;
        return llist;
    }
    
  • + 0 comments
         if (position == 0){
        if (head.next == null){
            return null;
        }
        else {
            return head.next;
        }
    }
    else {
        SinglyLinkedListNode current = head;
        for (int i = 0;i < position - 1; i++){
            current = current.next;
        }
        current.next = current.next.next;
        return head;
    }
    
    }
    
  • + 0 comments

    Why it's not working in C#.? Is there any way to resolve in C#??

  • + 0 comments

    JAVA Solution public static SinglyLinkedListNode deleteNode(SinglyLinkedListNode llist, int position) { // Write your code here

        int i=1;
        SinglyLinkedListNode temp = llist;
    
            if(position == 0) {
                    llist = llist.next;
                    return llist;
            } 
    
            while(temp.next.next != null && i < position){
                    temp = temp.next;
                    i++;
            }
    
            temp.next = temp.next.next;
            return llist;
    } 
    
  • + 0 comments

    Jeeze, second non-working template for C#.

    To make it work:

    Remove 'class Result' but keep its guts so that its guts are part of Solution class. Make deleteNode non-public (i.e. remove public keyword)