25 minutes
class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head == null || head.next == null) return head;
ListNode slow = head;
ListNode fast = head;
while(fast != null && slow != null){
if(slow.val != fast.val) {
slow.next = fast;
slow = fast;
}
if(slow.val == fast.val && fast.next == null){
slow.next = null;
return head;
}
fast = fast.next;
}
return head;
}
}