prev points to the
slow. If we do
slow.next = null then when there are only two elements left, it will be a infinite loop, since
slow will always point to the second node and
sort(head) will fail to divide the last two nodes and always result in the last two nodes, hence the stack overflow error.
I have a passion in designing and building product that could help people connect and society advance. I am also proud of my awesome leadership skills and communication skills as well!
Posts made by tony.mu101999
RE: Java merge sort solution