题目描述
Given a sorted circular linked list, the task is to insert a new node in this circular list so that it remains a sorted circular linked list.
Example 1:
Input:
LinkedList = 1->2->4
(the first and last node is connected,
i.e. 4 --> 1)
data = 2
Output: 1 2 2 4
Example 2:
Input:
LinkedList = 1->4->7->9
(the first and last node is connected,
i.e. 9 --> 1)
data = 5
Output: 1 4 5 7 9
Your Task:
The task is to complete the function sortedInsert() which should insert the new node into the given circular linked list and return the head of the linkedlist.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
0 <= N <= 10^{5}
输入格式
见题面
输出格式
见题面
样例输入
LinkedList = 1->2->4
(the first and last node is connected,
i.e. 4 --> 1)
data = 2
样例输出
1 2 2 4