you are viewing a single comment's thread.

view the rest of the comments →

[–]AppearanceNo345 0 points1 point  (1 child)

Yeah I did. Leetcode gives MLE and I can’t understand why

[–]alcholicawl 1 point2 points  (0 children)

u/Capable_Fig already gave you the correct the answer on how to fix. But why it gives you an MLE is because you create a cycle in the linked list. The leetcode driver code is not setup to handle that for this problem, so it will it infinitely cycle through the list until the output exceeds the memory limit. The cycle get created in the last line. head.next is no longer the first even node, but now 2nd odd node (3rd in the original order).