# Concise O(N), O(N) Java Solution without reversing the list

• Sorry, Since it's a recursive algorithm, it uses O(N) space. Thanks for pointing out this.

``````public class Solution {
public ListNode root;
}

boolean flag = true;
}
if (flag && root.val == head.val) {
root = root.next;
return true;
}
return false;
}
``````

}

• This post is deleted!

• with recursive call, we don't need to reverse the list.. very nice.

• Since you are using recursion, it can take O(n) stack space.

• I had the exact solution, but your solution is not O(1),since it uses recursive calls it needs to store all the previous values on to the stack thus it is O(n)

• Are we comparing the length of the list times in this solution?
maybe we can add something at the beginning of the function _isPlindrome like

• Every Node compared twice,add another flag to mark it can improve it.

啊啊，英语捉急〒_〒

• Don't worry. I can read Chinese.
Yeah, what you provide is a viable improvement.

• Haha, your conversation is really interesting! 莫名戳中笑点 :)

• You got that XD. 666666

• 看到这条回答笑了 XXXD

• @MarsMuYu You are coming here gaoxiao ma?

• There are always hidden laughters in Leetcode discussion :)

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