src/main/java/com/leetcode/design/medium/DesignLinkedList_707.java
public void addAtIndex(int index, int val) {
    if (index <= 0) {
      addAtHead(val);
      return;
    }

    Node node = head;

    while (index-- > 1 && node.next != null) {
      node = node.next;
    }

    if (index > 0) {
      return;
    }

    Node newNode = new Node(val);

    if (node.next != null) {
      newNode.next = node.next;
    }

    node.next = newNode;
  }
/**
   * Add a node of value val before the index-th node in the linked list. If index equals to the
   * length of linked list, the node will be appended to the end of linked list. If index is greater
   * than the length, the node will not be inserted.
   */
Add a node of value val before the index-th node in the linked list. If index equals to the
length of linked list, the node will be appended to the end of linked list. If index is greater
than the length, the node will not be inserted.
Add a node of value val before the index - th node in the linked list . If index equals to the length of linked list the node will be appended to the end of linked list . If index is greater than the length the node will not be inserted .
public void addAtIndex(int index, int val) {
    if (index <= 0) {
      addAtHead(val);
      return;
    }
    Node node = head;
    while (index-- > 1 && node.next != null) {
      node = node.next;
    }
    if (index > 0) {
      return;
    }
    Node newNode = new Node(val);
    if (node.next != null) {
      newNode.next = node.next;
    }
    node.next = newNode;
  }
public void addAtIndex ( int index , int val ) { if ( index <= 0 ) { addAtHead ( val ) ; return ; } Node node = head ; while ( index -- > 1 && node . next != null ) { node = node . next ; } if ( index > 0 ) { return ; } Node newNode = new Node ( val ) ; if ( node . next != null ) { newNode . next = node . next ; } node . next = newNode ; }
Add a node of value val before the index-th node in the linked list.
Add a node of value val before the index - th node in the linked list .