#!/usr/bin/env python # -*- coding: utf-8 -*- # author:sarizzm time:2021/1/6 0006 # Definition for singly-linked list. classListNode: def__init__(self, val=0, next=None): self.val = val self.next = next
classSolution:
defdeleteDuplicates(self, head): if head isNone: return head pre = head while pre.next: next_node = pre.next if pre.val == next_node.val: pre.next = next_node.next else: pre = next_node return head
defgenerateNode(nx): node = ListNode() p1 = node
for i in nx: p1.next = ListNode(i) p1 = p1.next return node.next