100% faster java code with comments for better understanding
\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val)
```\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNode(int val) { this.val = val; }\n *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode deleteDuplicates(ListNode head) {\n        ListNode dummy =new ListNode(0,head);\n        ListNode prev=dummy;\n        while(head!=null){\n            if(head.next!=null && head.val==head.next.val){\n                //skip that nodes\n                while(head.next!=null && head.val==head.next.val){\n                    head=head.next;\n                }\n                prev.next=head.next;  //prev\'s next point to the head next\n            }else{\n                prev=prev.next;\n            }\n            head=head.next;\n        }\n        return dummy.next;\n    }\n}\n```\nif it is helpful upvote please
['Linked List', 'Java']