I’m unable to understand the purpose of elements(list1). Isn’t elements a method for Counter class. What am I missing? Thanks.
Given two lists, A and B, the union is the list that contains elements or objects that belong to either A, B, or to both.
So, what we are doing is checking whether a list is empty or not. If it’s empty, then we are simply returning the other list, as a union is the collection of both lists. Since we are giving a proper implementation of the linked list, therefore we are not simply giving a solution as list1 or list2
.