You are viewing a single comment's thread. Return to all comments →
My Java solution with linear time complexity and constant space complexity:
public static SinglyLinkedListNode deleteNode(SinglyLinkedListNode llist, int position) { if(llist == null) return null; if(position == 0){ SinglyLinkedListNode newHead = llist.next; llist.next = null; return newHead; } SinglyLinkedListNode curr = llist; for(int i = 0; i < position; i++){ if(i == position - 1){ curr.next = curr.next.next; } else curr = curr.next; } return llist; }
Seems like cookies are disabled on this browser, please enable them to open this website
Delete a Node
You are viewing a single comment's thread. Return to all comments →
My Java solution with linear time complexity and constant space complexity: