Beats 100.00% of users with Java
Code\n\nclass Solution {\n    public ListNode deleteDuplicates(ListNode head) {\n        if (head == null || head.next == null)\n            return head;\n\n   
# Code\n```\nclass Solution {\n    public ListNode deleteDuplicates(ListNode head) {\n        if (head == null || head.next == null)\n            return head;\n\n        ListNode newHead = null;\n        ListNode tail = null;\n        int data = Integer.MIN_VALUE;\n        ListNode temp = head;\n\n        while (temp != null) {\n            if (temp.next != null && temp.val == temp.next.val) {\n                data = temp.val;\n                temp = temp.next;\n                continue;\n            }\n\n            if (temp.val != data) {\n                if (newHead == null) {\n                    newHead = temp;\n                    tail = temp;\n                } else {\n                    tail.next = temp;\n                    tail = temp;\n                }\n            }\n\n            temp = temp.next;\n        }\n\n        if (tail != null) {\n            tail.next = null;\n        }\n\n        return newHead;\n    }\n}\n\n```
['Linked List', 'Two Pointers', 'Java']