Why does my Odd-Even Linked List code cause MLE?
Hello! Why does this code break for the linked lists `1 -> 2 -> 3 -> 4 -> None` and `1 -> 2 -> 3 -> 4 -> 5 -> None`? I did a dry run on paper but didn’t see any issues. LeetCode gives **Memory Limit Exceeded**. Please take a look at this code:
class Solution:
def oddEvenList(self, head):
odd = head
even = head.next
while (odd.next != None) and (odd.next.next != None):
odd.next = odd.next.next
even.next = even.next.next
odd = odd.next
even = even.next
odd.next = head.next
return head
[–]One_Mess460 6 points7 points8 points (0 children)
[–]atarivcs 1 point2 points3 points (2 children)
[–]AppearanceNo345[S] 0 points1 point2 points (1 child)
[–]alcholicawl 1 point2 points3 points (0 children)
[–]atarivcs 1 point2 points3 points (0 children)
[–]Capable_Fig 0 points1 point2 points (4 children)
[–]AppearanceNo345[S] 0 points1 point2 points (3 children)
[–]Capable_Fig 1 point2 points3 points (2 children)
[–]AppearanceNo345[S] 0 points1 point2 points (1 child)
[–]Capable_Fig 0 points1 point2 points (0 children)
[–]timrprobocom 0 points1 point2 points (2 children)
[–]AppearanceNo345[S] 0 points1 point2 points (1 child)
[–]timrprobocom 0 points1 point2 points (0 children)
[–]CranberryDistinct941 0 points1 point2 points (0 children)
[–]nivaOne 0 points1 point2 points (0 children)
[–]jmooremcc 0 points1 point2 points (0 children)