Given a singly linked list of integers. The task is to check if each element in the linked list is present in a pair i.e. all elements occur even no. of times.
Input: 1 -> 2 -> 3 -> 3 -> 1 -> 2 Output: Yes Input: 10 -> 20 -> 30 -> 20 Output: No
- Initialise a temp node pointing to head.
- Take a variable to calculate XOR of all elements.
- Start traversing linked list and keep calculating the XOR with node->data.
- Return true if XOR is 0, else return false.
Below is the implementation of above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if a linked list is Circular Linked List
- Check if a pair with given product exists in Linked list
- Sum of all perfect numbers present in an Linked list
- Sum of all Palindrome Numbers present in a Linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
- Create new linked list from two given linked list with greater element at each node
- Linked List Pair Sum
- Partitioning a linked list around a given value and If we don't care about making the elements of the list "stable"
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
- Construct a Doubly linked linked list from 2D Matrix
- Check if binary representations of 0 to N are present as substrings in given binary string
- Sublist Search (Search a linked list in another list)
- Length of longest palindrome list in a linked list using O(1) extra space
- Rotate the sub-list of a linked list from position M to N to the right by K places
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.