javascript
/**
* Definition for singly-linked list.
* function ListNode(val, next) {
* this.val = (val===undefined ? 0 : val)
* this.next = (next===undefined ? null : next)
* }
*/
/**
* @param {ListNode} head
* @return {ListNode}
*/
var deleteDuplicates = function (head) {
if (head === null) {
return head
}
let firstNode = head
let value = firstNode.val
while (firstNode) {
while (firstNode.next && value === firstNode.next.val) {
firstNode.next = firstNode.next.next
}
firstNode = firstNode.next
value = firstNode?.val
}
return head
}