4ms simple c code


  • -1
    X

    /**

    • Definition for singly-linked list.

    • struct ListNode {

    • int val;
      
    • struct ListNode *next;
      
    • };
      /
      struct ListNode
      deleteDuplicates(struct ListNode* head) {
      struct ListNode *temp=head;

      while(temp&&temp->next)
      {
      if(temp->val == temp->next->val)
      temp->next = temp->next->next;
      else
      temp = temp->next;
      }
      return head;
      }


  • 1
    9

    You have to free the temp->next before it is assigned.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.