Simplify Non Palindrome Check at End

while (head is not None and head_second_half is not None):

Only head_second should be checked. This simplifies the code and makes it easier to explain and test! I’ve confirmed this works on the LC problem/tests.

Type your question above this line.


Hi @Akshay_Goel ,

Thank you so much for reaching out to us. Since we have a code snippet doing head = in the same while loop that is why for safety purposes we have checked head is not None because there could be any situation where it can be crashed.

And I have also applied your suggested changes in the code and it is working perfectly for that given use case but there could be a scenario where we need head is not None.