leetcode206 Reverse Linked List

基本单链表的反转

Class Solution

{

public:

  if(head == NULL || head != NULL)

    return head;

  ListNode *p = head;

  ListNode *q = head -> next;

  while(q)

  {

    ListNode *temp =  q -> next;

    q -> next = p;

    p = q;

    q = q -> next;

       }

  head -> next = NULL;

  return p;

}

你可能感兴趣的:(leetcode206 Reverse Linked List)