-
Notifications
You must be signed in to change notification settings - Fork 0
/
82.go
40 lines (36 loc) · 1011 Bytes
/
82.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
func deleteDuplicates(head *ListNode) *ListNode {
var (
list = &ListNode{Val: -101, Next: head}
now = list
)
if head == nil || head.Next == nil {
return head
}
for now.Next != nil && now.Next.Next != nil {
if now.Next.Val == now.Next.Next.Val {
for now.Next.Next != nil && now.Next.Val == now.Next.Next.Val {
now.Next.Next = now.Next.Next.Next
}
now.Next = now.Next.Next
} else {
now = now.Next
}
}
return list.Next
}
//func main() {
// root := &ListNode{Val: 1, Next: &ListNode{Val: 1, Next: &ListNode{Val: 1, Next: &ListNode{Val: 2, Next: &ListNode{Val: 3}}}}}
// root = deleteDuplicates(root)
// for root != nil {
// print(root.Val)
// root = root.Next
// }
// println()
// root = &ListNode{Val: 1, Next: &ListNode{Val: 2, Next: &ListNode{Val: 3, Next: &ListNode{Val: 3, Next: &ListNode{Val: 4, Next: &ListNode{Val: 4, Next: &ListNode{Val: 5}}}}}}}
// root = deleteDuplicates(root)
// for root != nil {
// print(root.Val)
// root = root.Next
// }
//}