C++,you should know how to use the Listnode.


  • 0
    B

    /**

    • Definition for singly-linked list.

    • struct ListNode {

    • int val;
      
    • ListNode *next;
      
    • ListNode(int x) : val(x), next(NULL) {}
      
    • };
      /
      class Solution {
      public:
      ListNode
      deleteDuplicates(ListNode* head) {
      if(head == NULL || head->next ==NULL)
      return head;
      ListNode *pt0 = head;
      ListNode *pt1 = pt0->next;

           while(pt0 && pt1)
           {
               if(pt0->val == pt1->val)
               {
                   ListNode *t = pt1;
                   pt0->next = pt1->next;
                   pt1 = pt1->next;
                   delete t; 
               }
               else
               {
                   pt0 = pt0->next;
                   pt1 = pt1->next;
               }
           }
           return head;
      

      }
      };


Log in to reply
 

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