题解 | #删除有序链表中重复的元素-II#
删除有序链表中重复的元素-II
https://www.nowcoder.com/practice/71cef9f8b5564579bf7ed93fbe0b2024
package main import . "nc_tools" /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func deleteDuplicates(head *ListNode) *ListNode { if head==nil||head.Next==nil{ return head } res :=&ListNode{} temp:=res m := map[int]int{} ints := []int{} for head!=nil { m[head.Val]++ ints = append(ints, head.Val) head=head.Next } for i, _ := range ints { if m[ints[i]]==1{ temp.Next=&ListNode{ Val: ints[i], } temp=temp.Next } } return res.Next }