83. 删除排序链表中的重复元素 leetcode
2018-11-02 本文已影响1人
出来遛狗了
image.png
/**
* Definition for singly-linked list.
* public class ListNode {
* public var val: Int
* public var next: ListNode?
* public init(_ val: Int) {
* self.val = val
* self.next = nil
* }
* }
*/
class Solution {
func deleteDuplicates(_ head: ListNode?) -> ListNode? {
if head.self == nil{
return head
}else{
var listN = head
while listN?.next != nil{
if listN?.val == listN?.next?.val{
listN?.next = listN?.next?.next
}else{
listN = listN?.next
}
}
}
return head
}
}