当前位置:网站首页>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;}}
边栏推荐
- QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution
- IDE compilation error: Dangling metacharacter
- EasyCVR接入海康大华设备选择其它集群服务器时,通道ServerID错误该如何解决?
- 【FPGA】SDRAM
- "Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
- 论文精度 —— 2017 CVPR《High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis》
- 阿里低代码框架 lowcode-engine 之自定义物料篇
- [Pdf generated automatically bookmarks]
- 电力机柜数据监测RTU
- 怎么删除语句审计日志?
猜你喜欢
CTO说MySQL单表行数不要超过2000w,为啥?
The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
大马驮2石粮食,中马驮1石粮食,两头小马驮一石粮食,要用100匹马,驮100石粮食,如何分配?
作业8.10 TFTP协议 下载功能
When EasyCVR is connected to the GB28181 device, what is the reason that the device is connected normally but the video cannot be played?
电商项目——商城限时秒杀功能系统
DNS separation resolution and intelligent resolution
电力机柜数据监测RTU
Idea (preferred) cherry-pick operation
Briefly, talk about the use of @Transactional in the project
随机推荐
"Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
this question in js
MongoDB 基础了解(二)
En-us is an invalid culture error solution when Docker links sqlserver
Description of ESB product development steps under cloud platform
2022-08-10 第六小组 瞒春 学习笔记
[BX]和loop
KingbaseES有什么办法,默认不读取sys_catalog下的系统视图?
高度塌陷问题的解决办法
【FPGA】SDRAM
Meaning of df and df -lh
程序化交易的策略类型可以分为哪几种?
The thirteenth day of learning programming
作业8.10 TFTP协议 下载功能
AI + medical: for medical image recognition using neural network analysis
Watch to monitor
Official release丨VS Code 1.70
Is there any way for kingbaseES to not read the system view under sys_catalog by default?
程序化交易改变了什么?
基于改进YOLOv5轻量化的烟火检测