Delete a Node HackerRank

public static SinglyLinkedListNode deleteNode(SinglyLinkedListNode head, int pos) {  

SinglyLinkedListNode temp=head;

        SinglyLinkedListNode old;
        int i=0;
        if(pos>0){
        while(i<pos-1){
            temp=temp.next;
            i++;
        }    
         old=temp.next.next;
       // temp.next.next=null;
         temp.next=old;
         return head;
        }
        else {
            old=temp.next;
            temp.next=null;
            head=old;
        return head;  
    }
        


Comments

Popular posts from this blog

Java Date And Time HackerRank

Recursive Sequence Geeks For Geeks Problem Of The Day 12-02-2024

Minimum Indices HackerEarth