diff --git a/83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.java b/83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.java new file mode 100644 index 0000000..126ecf7 --- /dev/null +++ b/83-remove-duplicates-from-sorted-list/83-remove-duplicates-from-sorted-list.java @@ -0,0 +1,26 @@ +/** + * Definition for singly-linked list. + * public class ListNode { + * int val; + * ListNode next; + * ListNode() {} + * ListNode(int val) { this.val = val; } + * ListNode(int val, ListNode next) { this.val = val; this.next = next; } + * } + */ +class Solution { + public ListNode deleteDuplicates(ListNode head) { + ListNode current = head; + while (current != null) { + ListNode next = current.next; + + while (next != null && current.val == next.val) { + next = next.next; + } + + current.next = next; + current = next; + } + return head; + } +} \ No newline at end of file