My solution is easy to understand


  • 0

    /**

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

Log in to reply
 

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