Skip to content

Latest commit

 

History

History
46 lines (26 loc) · 981 Bytes

0082.remove-duplicates-from-sorted-list-ii.md

File metadata and controls

46 lines (26 loc) · 981 Bytes

0082.Remove-Duplicates-from-Sorted-List-II

Description

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

Example 1:

Input: 1->2->3->3->4->4->5
Output: 1->2->5

Example 2:

Input: 1->1->1->2->3
Output: 2->3

Tags: Linked List

题意

给定一个有序的单链表,删除其中的重复元素。

题解

思路1

使用两个指针,一个指针指向当前元素,另一个指针指向前一个元素。 不断判断当前元素和下一个元素是否相等,如果相等,当前元素指向下一个,否则,令前一个指针指向当前节点的下一个节点。

思路2

思路2 ```go

```

结语

如果你同我一样热爱数据结构、算法、LeetCode,可以关注我 GitHub 上的 LeetCode 题解:awesome-golang-algorithm