Java code got MLE error.What's wrong with my code?


  • 0
    Y
    if (head == null || head.next == null) {
                return head;
            }
            ListNode temp = head;
            while (head.next != null) {
                head = head.next;
            }
            ListNode temp2 = head;
            while (temp.next != temp2) {
                head.next = temp;
                temp = temp.next;
                head = head.next;
            }
    
            return temp2;
    

    I can run this piece of code in my computer. But I got Memory Limit Exceeded error in case [1,2,3]. Can anyone help me?


  • 0
    Y

    oh sorry. I know the reason.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.