Given a circular linked list, write a method to insert a node at its tail. Return the list's head.
Examples:
*x = indicates head nodeInsert 1 ==> *1
Insert 2 ==> 1->2->*1
Insert 3 ==> 1->2->3->*1
1. Create a new ListNode
and point it's next
reference to itself.
2. If the head node is null
, simply return the new node.
3. Else, traverse the list until the next reference of the current node points to the head node.
4. Insert the new ListNode at this position.
public ListNode insertAtTail(ListNode head, int data) { }
C
Java
Python