当前位置:网站首页>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
};边栏推荐
- Unity camera control
- Read and save txt files
- VFPBS在IIS下调用EXCEL遇到的Access is denied
- Visualization of 3D geological model based on borehole data by map flapping software
- Chapter 11 advanced data management of OpenGL super classic (version 7)
- 【VCS+Verdi联合仿真】~ 以计数器为例
- Unity profiler performance analysis
- Redistemplate common method summary
- Unity screenshot method
- Unity obtains serial port data
猜你喜欢

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

图扑软件基于钻孔数据的三维地质模型可视化

终端便捷ssh(免密)连接

mmcv常用API介绍

Access is denied encountered when vfpbs calls excel under IIS

Installation and getting started with pytoch

【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example

Unity 3D model operation and UI conflict Scrollview

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

Remote sensing image /uda:curriculum style local to global adaptation for cross domain remote sensing image segmentation
随机推荐
Win10 vs2015 compiling curaengine
RedisTemplate 常用方法汇总
Leetcode 180 Consecutive numbers (2022.06.29)
很紧张,第一天做软件测试,需要做什么?
Gradient clip in dqn
The file has been downloaded incorrectly!
Set a plane to camera viewport
使用码云PublicHoliday项目判断某天是否为工作日
Pyinstaller flash back
Unity3d learning notes-1 (C # learning)
Unity multiple UI page turning left and right
Introduction to Redux: initial experience of Redux
The fourth day of learning C language for Asian people
Unity profiler performance analysis
Initial environment configuration of the list of OpenGL super classic (version 7) vs2019
After reading who moved my cheese
Some problems encountered in unity steamvr
Question mark (?) in Cron expression Use of
旋转框目标检测mmrotate v0.3.1入门
Pytorchcnn image recognition and classification model training framework