Insert into a Cyclic Sorted List
来源:互联网 发布:tv007网络电视在线直播 编辑:程序博客网 时间:2024/05/19 17:23
Given a node from a cyclic linked list which has been sorted, write a function to insert a value into the list such that it remains a cyclic sorted list. The given node can be any single node in the list. Return the inserted new node.
public class Solution { /** * @param node a list node in the list * @param x an integer * @return the inserted new list node */ public ListNode insert(ListNode node, int x) { if (node == null) { node = new ListNode(x); node.next = node; return node; } ListNode point = node; ListNode prev = null; //循环一个周期 do { prev = point; point = point.next; if (prev.val <= x && point.val >= x) { break; } if ((prev.val > point.val) && (x > prev.val || x < point.val)) { break; } } while (point != node); ListNode newNode = new ListNode(x); newNode.next = point; prev.next = newNode; return newNode; }}
0 0
- Insert into a Cyclic Sorted List
- Insert into a Cyclic Sorted List
- Insert into a Cyclic Sorted List
- Insert into a Cyclic Sorted List
- Insert into a Cyclic Sorted List
- 【Hackerrank】Insert a node into a sorted doubly linked list
- Insert in a sorted list
- Insert into a sorted circular linked list 环状链表 插入节点
- Python pandas insert list into a cell
- demo for insert values into sorted single list
- Insert Data into Sorted Table
- Insert Data into Sorted Table
- Insert a node in a sorted linked list.
- P21 (*) Insert an element at a given position into a list.
- P20 (*) P21 (*)Remove the Kth element from a list;Insert an element at a given position into a list.
- jquery insert a table into div
- 代码面试题:Insert Sorted Linked List
- Sorted insert for circular linked list
- .net 在配置文件中配置404路径出错
- Linux目录结构及解释(带图)
- c++ 字符串
- px和em,rem,pt的区别
- 文章标题
- Insert into a Cyclic Sorted List
- DB2 LOAD的三种模式 COPY NO, COPY YES和NONRECOVERABLE
- ubuntu12.04下配置NAT网络方式
- linux下清空连接跟踪表的方法
- KMP 字符串匹配 POJ 3461 Oulipo
- 【bzoj1012】[JSOI2008]最大数maxnumber
- java内存区域
- Elasticsearch5.5.2 安装教程
- hadoop2.6.5配置