leet-code/remove-duplicates-from-sort.../sol.go

23 lines
414 B
Go
Raw Permalink Normal View History

2022-06-04 22:46:52 +00:00
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
}