83. 删除排序链表中的重复元素

题目链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/

执行用时:20 ms, 在所有 Swift 提交中击败了99.44%的用户
内存消耗:13.5 MB, 在所有 Swift 提交中击败了75.28%的用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
func deleteDuplicates(_ head: ListNode?) -> ListNode? {
if head == nil || head?.next == nil{
return head
}
var cur = head
while cur?.next != nil {
//当前值与下一个节点值重复
if cur?.val == cur?.next?.val {
//使得当前节点指向下下一个节点
cur?.next = cur?.next?.next
}else {
//不相等则移动当前指针
cur = cur?.next
}
}
return head
}
}

83. 删除排序链表中的重复元素
https://pisces34.github.io/2021/09/27/leetcode/83/
发布于
2021年9月27日
许可协议