Java Solution, 0 ms, Beats 100%
Java Code\n\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     int val;\n *     ListNode next;\n *     ListNode() {}\n *     ListNo
# Java Code\n```\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        if (head == null) return null;\n\n        ListNode ans = new ListNode();\n        ans.next = head;\n\n        ListNode ptr = ans;\n\n        while (ptr.next != null && ptr.next.next != null) {\n\n            if (ptr.next.val == ptr.next.next.val) {\n                int value = ptr.next.val;\n                while (ptr.next != null && ptr.next.val == value) {\n                    ptr.next = ptr.next.next;\n                }\n            } else {\n                ptr = ptr.next;\n            }\n        }\n        return ans.next;\n    }\n}\n```
['Linked List', 'Two Pointers', 'Java']