Why does My solution show "Memory Limit Exceeded "?

  • 0
    public class Solution {
    public ListNode reverseList(ListNode head) {
        if(head == null) return head;
        ListNode point = head.next;
        ListNode tmp;
            tmp = point;
            point = point.next;
            tmp.next = head;
            head = tmp;
        return head;


  • 0

    I ran into this same issue. Right now there's a loop when you follow the 'next' path between the original first and second element -- the two elements' 'next' variables point to each other.

  • 1

    In the "tmp = point", you make "tmp" points to head.next.
    then in the "tmp.next = head", you make "tmp.next" points to head.
    So we have a circle linked list with two elements .
    And I think OJ calls this situation as " MLE " during testing the output.

Log in to reply

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