# I think LeetCode lack of test cases for Linked List Cycle in this problem

• In this problem, I think we need to consider the Linked List Cycle.

For example, if there have 3 ListNode: A(3), B(4), C(5), A->next = B, B->next = C, C->next = A, and the value which we want remove is 4, the result should be: A->next = C, C->next = A.

But when I submit a solution does not consider this issue, it also passed all the test cases and have Accepted. I think this is a mistake.

Consider Linked List Cycle (It has been Accepted):

``````class Solution {
public:
ListNode *removeElements(ListNode *head, int val) {
ListNode *tmp = head;
while (tmp && tmp->val == val && tmp->next != head)
tmp = tmp->next;
if (!tmp || (tmp->next == head && tmp->val == val))
return NULL;
int size = 0;
while (tmp && tmp != head) {
++size;
tmp = tmp->next;
}
for (; size > 0; --size)
if (tmp->next->val == val)
tmp->next = tmp->next->next;
else
tmp = tmp->next;
}
};
``````

Does Not Consider Linked List Cycle (It has also been Accepted):

``````class Solution {
public:
ListNode *removeElements(ListNode *head, int val) {
return NULL;
ListNode *tmp = head;
while (tmp)
if (tmp->next && tmp->next->val == val)
tmp->next = tmp->next->next;
else
tmp = tmp->next;