function ListNode(val, next) {
this.val = (val === undefined ? 0 : val)
this.next = (next === undefined ? null : next)
}
var deleteDuplicates = function (head) {
let map = new Map()
let cur = head
while (cur) {
if (map.has(cur.val)) {
map.set(cur.val, map.get(cur.val) + 1)
} else {
map.set(cur.val, 1)
}
cur = cur.next
}
let prehead = new ListNode()
cur = prehead
while (head) {
let count = map.get(head.val)
if (count === 1) {
cur.next = new ListNode(head.val)
cur = cur.next
}
head = head.next
}
return prehead.next
};
var deleteDuplicates = function (head) {
let prehead = new ListNode()
prehead.next = head
let cur = prehead
while (cur.next && cur.next.next) {
if (cur.next.val === cur.next.next.val) {
let val = cur.next.val
while (cur.next && cur.next.val === val) {
cur.next = cur.next.next
}
} else {
cur = cur.next
}
}
return prehead.next
}