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) {
if(head == null){
return head;
}
ListNode temp = head;
while(temp.next != head){
temp = temp.next;
}
temp.next = head.next;
head.next = null;
head = temp.next;
return head;
}
head.next == head
. You'll be stuck in an infinite loop if that happens. \$\endgroup\$