微信公众号:三木小小推[1]
系列:刷题之Python
如果你觉得该系列对你有帮助,欢迎点好看[2]
问题描述
给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例 1:
输入: 1->1->2
输出: 1->2
示例 2:
输入: 1->1->2->3->3
输出: 1->2->3
解决方案
class Solution:
def deleteDuplicates(self, head):
if head == None:
return
cur_node = head
while cur_node.next is not None:
if cur_node.val == cur_node.next.val:
cur_node.next = cur_node.next.next
else:
cur_node = cur_node.next
return head
欢迎订阅
下面是三木小小推的二维码,欢迎订阅呦~~


文章转载自三木小小推,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




