c++ solution (9 ms)


  • 0
    class Solution {
    public:
      ListNode* deleteDuplicates(ListNode* head) {
        if (head == NULL) return head;
        ListNode* cur = head;
        while (cur->next != NULL) {
          if (cur->val == cur->next->val)
            cur->next = cur->next->next;
          else
            cur = cur->next;
        }
        return head;
      }
    };
    

  • 0
    P
    This post is deleted!

Log in to reply
 

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