Remove all occurences of duplicates in a linked list | Problem of the day | GeeksForGeeks

  Рет қаралды 97

Mathematics

Mathematics

Күн бұрын

Given a sorted linked list, delete all nodes that have duplicate numbers (all occurrences), leaving only numbers that appear once in the original list, and return the head of the modified linked list.
Examples:
Input: Linked List = 23-28-28-35-49-49-53-53
Output: 23 35
Explanation:
The duplicate numbers are 28, 49 and 53 which are removed from the list.
Input: Linked List = 11-11-11-11-75-75
Output: Empty list
Explanation:
All the nodes in the linked list have duplicates. Hence the resultant list would be empty.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Table of Contents
0:00 Problem Statement
0:50 Solution
8:50 Solution - Example
14:15 Pseudo Code
17:33 Python Code
18:55 C++ Code

Пікірлер: 3
@mathematics3398
@mathematics3398 Ай бұрын
Table of Contents 0:00 Problem Statement 0:50 Solution 8:50 Solution - Example 14:15 Pseudo Code 17:33 Python Code 18:55 C++ Code
@mathematics3398
@mathematics3398 Ай бұрын
class Solution: def removeAllDuplicates(self, head): new_head = save = Node(-1) prvs = head ptr = head.next del_prvs = False new_head.next = head while ptr: next = ptr.next if prvs.data == ptr.data: prvs.next = ptr.next ptr.next = None del_prvs = True elif del_prvs: del_prvs = False save.next = ptr prvs = ptr else: save = prvs prvs = ptr ptr = next if del_prvs: save.next = None return new_head.next
@mathematics3398
@mathematics3398 Ай бұрын
Table of Contents 0:00 Problem Statement 0:50 Solution 8:50 Solution - Example 14:15 Pseudo Code 17:33 Python Code 18:55 C++ Code
Linked lists in 4 minutes
4:22
Michael Sambol
Рет қаралды 66 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 29 МЛН
ТЫ С ДРУГОМ В ДЕТСТВЕ😂#shorts
01:00
BATEK_OFFICIAL
Рет қаралды 6 МЛН
L6. Odd Even Linked List | Multiple Approaches
24:05
take U forward
Рет қаралды 72 М.
Form a palindrome | Problem of the Day | GeeksForGeeks
17:46
Rat in a Maze Problem I | Problem of the Day | GeeksForGeeks
19:00
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 863 М.
Stop, Intel’s Already Dead! - AMD Ryzen 9600X & 9700X Review
13:47
Linus Tech Tips
Рет қаралды 980 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 634 М.
L25. Merge K Sorted Lists | Multiple Approaches
30:02
take U forward
Рет қаралды 35 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 29 МЛН