leetcode删除排序链表中的重复元素python

给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。
示例:
输入: 1->1->2
输出: 1->2
输入: 1->1->2->3->3
输出: 1->2->3

class Solution(object):    
	def deleteDuplicates(self, head):        
"""        
:type head: ListNode        
:rtype: ListNode        
"""        
		if head == None:            
		    return None        
		point=head        
		while point.next:            
		    if(point.val==point.next.val):                
		        point.next=point.next.next            
		    else:                
		        point=point.next        
		return head
发布了29 篇原创文章 · 获赞 28 · 访问量 299

猜你喜欢

转载自blog.csdn.net/weixin_45398265/article/details/104741893
今日推荐