当前位置:网站首页>Enter the starting position, the ending position intercepts the linked list
Enter the starting position, the ending position intercepts the linked list
2022-08-11 03:33:00 【这是一本书】
1 Background
Enter m n , linked list, and get a linked list with starting point m and ending point n
2 Problem-solving ideas
1) First, get N nodes according to the input n, see this article for details
https://blog.csdn.net/an13654067079/article/details/126173743
2) m node, n node m node as the head of the new linked list
3) The previous node of the m node mPre.next = null
The next node of n nodes nNext.next = null
The new linked list is intercepted, the problem is not difficult
public static void main(String[] args) {ListNode listNode = ListNodeUtil.getListNode();int m = 2;int n = 4;//Get m nodes, n nodesListNode mNode = index(listNode, m);ListNode nNode = index(listNode, n);if(m!=1){//Get the previous node of mint mPre = m-1;ListNode mPreNode = index(listNode, mPre);mPreNode.next = null;}ListNode nNextNode = nNode.next;nNode.next = null;System.out.println(mNode);}/*** Get the node at the specified location** @param listNode* @param index* @return*/public static ListNode index(ListNode listNode , int index){ListNode dummyNode = new ListNode();dummyNode.setVal(0);dummyNode.setNext(listNode);int n = 1;for(int i = 0 ; i< index; i++){dummyNode = dummyNode.getNext();}return dummyNode;}import lombok.Data;@Datapublic class ListNode {/*** current node value*/public int val;/*** next node*/public ListNode next ;}public class ListNodeUtil {/*** Get the linked list** @return*/public static ListNode getListNode(){ListNode one = new ListNode();one.setVal(1);ListNode two = new ListNode();two.setVal(2);ListNode three = new ListNode();three.setVal(3);ListNode four = new ListNode();four.setVal(4);ListNode five = new ListNode();five.setVal(5);one.setNext(two);two.setNext(three);three.setNext(four);four.setNext(five);return one;}}边栏推荐
- 什么是三方支付?
- How can users overcome emotional issues in programmatic trading?
- STC8H development (15): GPIO drive Ci24R1 wireless module
- Environment configuration of ESP32 (arduino arduino2.0 VScode platform which is easy to use?)
- E-commerce project - mall time-limited seckill function system
- What problems should we pay attention to when building a programmatic trading system?
- 常用认证机制
- oracle的基数会影响到查询速度吗?
- EasyCVR接入海康大华设备选择其它集群服务器时,通道ServerID错误该如何解决?
- VIT 源码详解
猜你喜欢

二叉树相关代码题【较全】C语言

The most unlucky and the luckiest

console.log alternatives you didn't know about

DNS分离解析和智能解析

Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array

AI+Medical: Using Neural Networks for Medical Image Recognition and Analysis

互换性测量技术-几何误差

高校就业管理系统设计与实现

Qnet Weak Network Test Tool Operation Guide

Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use
随机推荐
E-commerce project - mall time-limited seckill function system
console.log alternatives you didn't know about
The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
Is there any way for kingbaseES to not read the system view under sys_catalog by default?
【FPGA】SDRAM
常用认证机制
【愚公系列】2022年08月 Go教学课程 036-类型断言
用户如何克服程序化交易中的情绪问题?
watch监听
The 125th day of starting a business - a note
【C语言】入门
Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
FTP错误代码列表
The thirteenth day of learning programming
Typescript study notes | Byte Youth Training Notes
Leetcode 669. 修剪二叉搜索树
"Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
Qnet弱网测试工具操作指南
font
高校就业管理系统设计与实现