Practice/Meta/Leetcode 708. Insert into a Sorted Circular Linked List
CodingMust
You are given a reference to a node in a sorted circular linked list. The list is sorted in ascending order, and the last node points back to the first node, forming a circle.
Your task is to insert a new value into this circular list while maintaining the sorted order. After insertion, return a reference to any node in the modified list.
The circular linked list may be empty (given as None), in which case you should create a new single-node circular list.
Example 1:
Input: head = [1, 3, 5], insertVal = 4 Output: [1, 3, 4, 5] Explanation: The value 4 fits between 3 and 5 in sorted order.
Example 2:
Input: head = [1, 3, 5], insertVal = 0 Output: [0, 1, 3, 5] Explanation: 0 is the new minimum and should be inserted at the wrap-around point (after 5, before 1).
Example 3:
Input: head = [], insertVal = 1 Output: [1] Explanation: The list is empty, so we create a new node that points to itself.
Example 4:
Input: head = [3, 3, 3], insertVal = 3 Output: [3, 3, 3, 3] Explanation: When all values are equal, we can insert anywhere.