From fe949d97f0dae580e87a0bb80626c150878ab558 Mon Sep 17 00:00:00 2001 From: Sukshan01 <101926757+Sukshan01@users.noreply.github.com> Date: Fri, 28 Oct 2022 22:57:10 +0530 Subject: [PATCH] Delete duplicate nodes from a sorted linked list --- removeDuplicates.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 removeDuplicates.java diff --git a/removeDuplicates.java b/removeDuplicates.java new file mode 100644 index 0000000..5896ff9 --- /dev/null +++ b/removeDuplicates.java @@ -0,0 +1,24 @@ +public static SinglyLinkedListNode removeDuplicates(SinglyLinkedListNode llist) { + // Write your code here + + if(llist == null){ + return llist; + } + + SinglyLinkedListNode new_head = llist; + + while(llist.next != null){ + + if(llist.data == llist.next.data){ + + llist.next = llist.next.next; + } + + else{ + llist = llist.next; + } + } + + return new_head; + + }