Why space complexity is O(1), not O(N)?

From my perspective, the solution used extra O(N/2) space to store the copy of the second half of the given single linked list, then why the space complexity is O(1)? Thanks.

1 Like

Actually no.
This statement might be confusing
copyHeadSecondHalf = headSecondHalf

But it’s just a single node and just a ref to node.