/*
// Definition for a Node.
class Node {
public int val;
public Node next;
public Node() {}
public Node(int _val) {
val = _val;
}
public Node(int _val, Node _next) {
val = _val;
next = _next;
}
};
*/
class Solution {
public Node insert(Node head, int insertVal) {
Node node = new Node(insertVal);
//空
if (head == null){
node.next = node;
return node;
}
//单节点
if (head.next == head) {
head.next = node;
node.next = head;
return head;
}
Node left= head;
Node right = head.next;
//重复值
while (right != head) {
if(insertVal>=left.val&&insertVal<=right.val){
break;
}
if (left.val > right.val) {
if (insertVal > left.val || insertVal < right.val) {
break;
}
}
left=left.next;
right=left.next;
}
Node insert =new Node(insertVal,right);
left.next=insert;
return head;
}
}
循环单调非递减列表
left<right:要求 left<insert<right
最后节点:left>right:插入点比left大或者比right小,则在此处插入