Skip to content

Commit

Permalink
Create 83. Remove Duplicates from Sorted List.java
Browse files Browse the repository at this point in the history
  • Loading branch information
SharmaTushar1 authored Jun 14, 2022
1 parent 5be3c73 commit 00db47c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions java/83. Remove Duplicates from Sorted List.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 00db47c

Please sign in to comment.