From 00db47c5a14b54c5860f4090bd5e956cc283f0d8 Mon Sep 17 00:00:00 2001 From: Tushar Sharma <62995185+SharmaTushar1@users.noreply.github.com> Date: Tue, 14 Jun 2022 18:00:12 +0530 Subject: [PATCH] Create 83. Remove Duplicates from Sorted List.java --- ...3. Remove Duplicates from Sorted List.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 java/83. Remove Duplicates from Sorted List.java diff --git a/java/83. Remove Duplicates from Sorted List.java b/java/83. Remove Duplicates from Sorted List.java new file mode 100644 index 000000000..e7362e299 --- /dev/null +++ b/java/83. Remove Duplicates from Sorted List.java @@ -0,0 +1,20 @@ +//Three pointer approach that we use in in-place reversal of linked list. + +class Solution { + public ListNode deleteDuplicates(ListNode head) { + ListNode p = null; + ListNode q = null; + ListNode r = head; + while (r!=null) { + if (q!=null && q.val == r.val) { + r = r.next; + q.next = r; + }else { + p = q; + q = r; + r = r.next; + } + } + return head; + } +}