当前位置:网站首页>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;}}边栏推荐
- AI+医疗:使用神经网络进行医学影像识别分析
- Qnet Weak Network Test Tool Operation Guide
- [ADI low-power 2k code] Based on ADuCM4050, ADXL363, TMP75 acceleration, temperature detection and serial port printing, buzzer playing music (lone warrior)
- The 125th day of starting a business - a note
- 互换性测量技术-几何误差
- Traversal of DOM tree-----modify styles, select elements, create and delete nodes
- Will oracle cardinality affect query speed?
- Idea (preferred) cherry-pick operation
- 2022-08-10 第六小组 瞒春 学习笔记
- 二叉树相关代码题【较全】C语言
猜你喜欢

QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution

Interchangeability Measurements and Techniques - Calculation of Deviations and Tolerances, Drawing of Tolerance Charts, Selection of Fits and Tolerance Classes

互换性与测量技术——表面粗糙度选取和标注方法

EasyCVR接入GB28181设备时,设备接入正常但视频无法播放是什么原因?

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

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

Qnet Weak Network Test Tool Operation Guide
![[DB operation management/development solution] Shanghai Daoning provides you with an integrated development tool to improve the convenience of work - Orange](/img/3e/06654c5ad976bad53bf0aa4390e7e9.png)
[DB operation management/development solution] Shanghai Daoning provides you with an integrated development tool to improve the convenience of work - Orange

Build Zabbix Kubernetes cluster monitoring platform

Official release丨VS Code 1.70
随机推荐
多串口RS485工业网关BL110
App基本框架搭建丨日志管理 - KLog
“顶梁柱”滑坡、新增长极难担重任,阿里“蹲下”是为了跳更高?
高校就业管理系统设计与实现
2022-08-10 第六小组 瞒春 学习笔记
How to rebuild after pathman_config and pathman_config_params are deleted?
The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
高度塌陷问题的解决办法
Homework 8.10 TFTP protocol download function
A simple JVM tuning, learn to write it on your resume
7 sorting algorithms that are often tested in interviews
按摩椅控制板的开发让按摩椅变得简约智能
pathman_config、pathman_config_params 删除后,如何重建?
互换性与测量技术——表面粗糙度选取和标注方法
字体反扒
Watch to monitor
【FPGA】day22-SPI协议回环
Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use
QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution
Is Redis old?Performance comparison between Redis and Dragonfly