✔️ 100% Fastest TypeScript Solution
\n/**\n * Definition for singly-linked list.\n * class ListNode {\n *     val: number\n *     next: ListNode | null\n *     constructor(val?: number, next?: Lis
```\n/**\n * Definition for singly-linked list.\n * class ListNode {\n *     val: number\n *     next: ListNode | null\n *     constructor(val?: number, next?: ListNode | null) {\n *         this.val = (val===undefined ? 0 : val)\n *         this.next = (next===undefined ? null : next)\n *     }\n * }\n */\n\nfunction deleteDuplicates(head: ListNode | null): ListNode | null {\n  if (!head) { return null }\n  if (!head.next) { return head }\n  let fakeHead = new ListNode(undefined, head) // beginning of a returned linked list\n  let prev = fakeHead // start of the group with same values\n  let current = head // pointer\n\n  while (current) { // move through the current group until new value is seen\n    while (current.next && prev.next && prev.next.val === current.next.val) { current = current.next }\n\n    if (prev.next === current) {\n      prev = prev.next // if group has only one member, move prev to current\n    } else {\n      prev.next = current.next // otherwise, exclude the group\n    }\n\n    current = current.next as ListNode // Move to the next node\n  }\n\n  return fakeHead.next\n}\n```\n\nLet me know in comments if you have any doubts. I will be happy to answer.\n\nPlease upvote if you found the solution useful.
['TypeScript', 'JavaScript']