leetcode/src/main/java/com/my/MyLinkedList.java
/** Delete the index-th node in the linked list, if the index is valid. */
Delete the index-th node in the linked list, if the index is valid.
Delete the index - th node in the linked list if the index is valid .
public void deleteAtIndex(int index) {
        if(index == 0){
            head = head.next;
        }else if(index>0 && index<listIndex){
            SingleNode temp = head;
            for (int i =1 ;i<index;i++){
                if(temp.next != null){
                    temp = temp.next;
                }
            }
            SingleNode nextTemp = temp.next.next;
            temp.next = nextTemp;
            if(index == listIndex-1){
                tail = temp;
            }
            listIndex --;
        }
    }
public void deleteAtIndex ( int index ) { if ( index == 0 ) { head = head . next ; } else if ( index > 0 && index < listIndex ) { SingleNode temp = head ; for ( int i = 1 ; i < index ; i ++ ) { if ( temp . next != null ) { temp = temp . next ; } } SingleNode nextTemp = temp . next . next ; temp . next = nextTemp ; if ( index == listIndex - 1 ) { tail = temp ; } listIndex -- ; } }
Delete the index-th node in the linked list, if the index is valid.
Delete the index - th node in the linked list if the index is valid .