Today I tackled this coding challenge:

Given a circular linked list, implement a method to delete its head node. Return the list's new head node.

I would appreciate any feedback.

public ListNode deleteAtHead(ListNode head) {

}

temp = temp.next;
}

}

• You don't handle a single element list where head.next == head. You'll be stuck in an infinite loop if that happens. – mdfst13 Mar 19 '17 at 20:28

Since you are dealing with a circularly linked list (meaning the tail's next points to head and the head's prev points to the tail) and assuming each node has a prev and next, you might consider this easier approach which does not require traversal of the entire list.

public ListNode deleteAtHead(ListNode head) {
}


This should also work for a list with only 1 node (e.g. a head) assuming it is initialized with prev and next referencing itself.
• this doesn't actually correctly solve the given assignment. for head.next == head the correct return value is null, which doesn't happen with your code :/ – Vogel612 Mar 21 '17 at 9:03