remove-duplicates-from-sorted-list

This commit is contained in:
Gleb Koval 2022-06-04 23:46:52 +01:00
parent 4e9d897bd9
commit c2c2efa88d
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package main
type ListNode struct {
Val int
Next *ListNode
}
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
func deleteDuplicates(head *ListNode) *ListNode {
for current := head; current != nil; current = current.Next {
for current.Next != nil && current.Val == current.Next.Val {
current.Next = current.Next.Next
}
}
return head
}