Candidate: Using a stack would make it O(n) space. The optimal solution uses O(1) space.
Anonymous: Your answer will always return NULL because your exit condition is for head == null and then you return head.
I don't think the below is optimal - feels like I should be able to eliminate at least one variable:
void reverseList(Node **ppHead)
{
ASSERT(ppHead != NULL);
if(!ppHead)
{
return;
}
Node *pPrev = NULL;
Node *pCur = *ppHead;
while(pCur)
{
Node *pNext = pCur->pNext;
pCur->pNext = pPrev;
pPrev = pCur;
pCur = pNext;
}
*ppHead = pCur;
}