当前位置:网站首页>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;}}边栏推荐
- Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
- Leetcode 108. 将有序数组转换为二叉搜索树
- Unity2D animation (1) introduction to Unity scheme - animation system composition and the function of use
- Homework 8.10 TFTP protocol download function
- The thirteenth day of learning programming
- Qnet Weak Network Test Tool Operation Guide
- 阿里低代码框架 lowcode-engine 之自定义物料篇
- 【FPGA】SDRAM
- 2022-08-10 第六小组 瞒春 学习笔记
- 互换性与测量技术——表面粗糙度选取和标注方法
猜你喜欢

Redis老了吗?Redis与Dragonfly性能比较

基于改进YOLOv5轻量化的烟火检测

C语言之自定义类型------结构体

2022-08-10 第六小组 瞒春 学习笔记

Homework 8.10 TFTP protocol download function

【愚公系列】2022年08月 Go教学课程 036-类型断言

Qnet Weak Network Test Tool Operation Guide
![[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface](/img/cb/41e5f553b0b776dccf0e39f9bf377f.png)
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface

Description of ESB product development steps under cloud platform

Traversal of DOM tree-----modify styles, select elements, create and delete nodes
随机推荐
2022-08-10 The sixth group Hiding spring study notes
Typescript study notes | Byte Youth Training Notes
Homework 8.10 TFTP protocol download function
浅析一下期货程序化交易好还是手工单好?
互换性与测量技术——表面粗糙度选取和标注方法
Window function application of sum and count
你不知道的 console.log 替代品
Kubernetes集群搭建Zabbix监控平台
Talk about the understanding of RPC
元素的BFC属性
CSDN 博客更换皮肤
The negative semantic transformation layer
pathman_config、pathman_config_params 删除后,如何重建?
IDE compilation error: Dangling metacharacter
Goodbye Chongqing paper invoices!The issuance of electronic invoices for accommodation expenses will soon completely replace the invoices of hotels, catering and gas stations
A large horse carries 2 stone of grain, a middle horse carries 1 stone of grain, and two ponies carry one stone of grain. It takes 100 horses to carry 100 stone of grain. How to distribute it?
KingbaseES有什么办法,默认不读取sys_catalog下的系统视图?
Qnet弱网测试工具操作指南
Rotary array problem: how to realize the array "overall reverse, internal orderly"?"Three-step conversion method" wonderful array
Goodbye Chengdu paper invoices!The issuance of electronic invoices for accommodation expenses will soon completely replace the invoices of hotels, catering and gas stations