P18224 [GeeksforGeeks] Delete all occurrences of a given key in a doubly linked list
普及
题目描述

You are given the head of a doubly Linked List and a Key. Your task is to delete all occurrences of the given key and return the new DLL.
Example:
Input:
2<->2<->10<->8<->4<->2<->5<->2
2
Output:
10<->8<->4<->5
Explanation:
All Occurences of 2 have been deleted.
Your Task:
Complete the function void deleteAllOccurOfX(struct Node** head_ref, int key), which takes the reference of the head pointer and an integer value key. Delete all occurrences of the key from the given DLL.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
0<=Number of Nodes<=10^{4}
-10^{3}<=Node Value <=10^{3}

输入格式

见题面

输出格式

见题面

样例输入
2<->2<->10<->8<->4<->2<->5<->2 2
样例输出
10<->8<->4<->5