当前位置:网站首页>Delete the repeating elements in the sorting list (simple questions)
Delete the repeating elements in the sorting list (simple questions)
2022-06-30 05:22:00 【I won't download the software when I arrive】
Before doing this topic , You need to have some prerequisite knowledge about the linked list first , Make one here JavaScript There is a supplement to the linked list .
The first thing to be clear is :
Although the linked list looks like an array , But linked lists and arrays are different !!! Not a data structure !
The positions of linked list elements in memory are not continuous ( Arrays are contiguous storage ), Each element consists of a node that stores the element itself and a reference to the next element ( Also called pointer or link ) form .
For a more convenient understanding , Here is an example diagram :

( This is a 3 Single linked list of elements )
Because of this characteristic , The linked list is being deleted , It is much more convenient to insert than array !item Save the data ,next Save the reference of the next linked list .
Inserting a linked list is easier than an array , Here is an example diagram :

What we need to do is to specify the location of the linked list element to be inserted into the linked list next The value refers to the element that needs to be inserted data value , While inserting elements next Value points to the next element of the inserted element data value ;
Code shows :
function insert ( newElement , item ) {
var newNode = new Node( newElement );
var currNode = this.find( item );
newNode.next = currNode.next;
currNode.next = newNode;
}Deleting a linked list is very similar to inserting a linked list , So just give an example diagram :

The following is a description of the title :
Given the header of a sorted linked list head , Delete all duplicate elements , Make each element appear only once . return Sorted linked list .
Example diagram description :
Their thinking :
Find repeating elements
var deleteDuplicates = function(head) {
var fir=head
while(fir && fir.next){
if(fir.val ==fir.next.val){
fir.next=fir.next.next
}else{
fir=fir.next
}
}
return head
};边栏推荐
- Responsive layout
- Nestjs入门和环境搭建
- Visualization of 3D geological model based on borehole data by map flapping software
- Another download address for typro
- 如何写论文
- 【VCS+Verdi联合仿真】~ 以计数器为例
- 3D rotation album
- Postman 做测试的 6 个常见问题
- C # uses monopinvokecallback to directly call back C # function
- Procedural animation -- inverse kinematics of tentacles
猜你喜欢

Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation

旋转框目标检测mmrotate v0.3.1入门

3D rotation album

East Tower attack and defense world - XSS bypasses the safety dog

Xctf--Web--Challenge--area Wp

【LeetCode】Easy | 232. Using stack to realize queue (pure C manual tearing stack)

Procedural animation -- inverse kinematics of tentacles

PWN入门(2)栈溢出基础

Win10 vs2015 compiling curaengine

Unity- the camera follows the player
随机推荐
Chapter 8 primitive processing of OpenGL super classic (version 7)
企事业单位源代码防泄露工作该如何进行
GoLand No Tests Were Run : 不能使用 fmt.Printf() <BUG>
Revit Secondary Development - - Project use Panel features not opened
Procedural animation -- inverse kinematics of tentacles
MinGW-w64下载文件失败the file has been downloaded incorrectly!
Ugui uses its own function to realize reverse mask
[recruitment] UE4 Development Engineer
Leetcode 180 Consecutive numbers (2022.06.29)
终端便捷ssh(免密)连接
Unity supports the platform # define instruction of script
Golan no tests were run: fmt Printf() < BUG>
VFPBS上传EXCEL并保存MSSQL到数据库中
Very nervous. What should I do on the first day of software testing?
Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation
Tensorflow2 of ubantu18.04 X installation
mmdet之Loss模块详解
14x1.5cm vertical label is a little difficult, VFP calls bartender to print
Unit asynchronous jump progress
2021-07-29 compilation of Cura in ubantu18.04