C++ solution


  • 0
    C

    /**

    • 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) {
      ListNode* start=head;
      while(start && start->next)
      {
      if(start->val==start->next->val)
      {
      start->next=start->next->next;
      }
      else
      start=start->next;
      }
      return head;
      }
      };

Log in to reply
 

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