Leetcode 83 Remove Duplicates from Sorted List Solution in java | Hindi Coding Community

0

 


Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.


Input: head = [1,1,2,3,3]

Output: [1,2,3]


class Solution {
public ListNode deleteDuplicates(ListNode head) {
if(head == null || head.next == null)return head;
head.next = deleteDuplicates(head.next);
return head.val == head.next.val ? head.next : head;
}
}

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !