Created
April 6, 2019 11:51
-
-
Save Ahmah2009/2aefab238d3baae7d49549c7f1372866 to your computer and use it in GitHub Desktop.
82. Remove Duplicates from Sorted List II leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func deleteDuplicates(head *ListNode) *ListNode { | |
if head == nil{ | |
return head | |
} | |
tempNode := &ListNode{Val: head.Val-1, Next:head} | |
node:=tempNode | |
fast := tempNode.Next | |
for node.Next!=nil && fast.Next!=nil{ | |
if fast.Val ==fast.Next.Val{ | |
temp := fast | |
for temp!=nil && temp.Val ==fast.Val{ | |
temp=temp.Next | |
} | |
node.Next=temp | |
fast= temp | |
}else{ | |
node = node.Next | |
fast = fast.Next | |
} | |
} | |
return tempNode.Next | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment