My slower two submissions.


  • 0
    L

    ListNode* deleteDuplicates(ListNode* head)
    {
    // 第一种写法 beats 55.33%
    if(head == nullptr)
    return nullptr;
    ListNode * scan = head;
    while(scan)
    {
    while(scan->next != nullptr && scan->val == scan->next->val) // 当前节点值与前一个节点值相等,跳过到下一个节点
    scan->next = scan->next->next;
    scan = scan->next; // 遍历整个链表
    }
    return head;

      // 第二种写法 beats 27.2%
      /*
        if(head == nullptr)
            return nullptr;
       ListNode * scan = head;
       while(scan && scan->next)
       {
           if(scan->val == scan->next->val)
                scan->next = scan->next->next;  // 与前一个节点重复则检查下下个节点
           else
                scan = scan->next;             // 不重复则依次遍历
       }
       return head;
       */

  • 0
    L
    This post is deleted!

  • 0
    L

    @liuxiang said in My slower two submissions.:

    @liuxiang said in My slower two submissions.:

    ListNode* deleteDuplicates(ListNode* head)
    {
    // 第一种写法 beats 55.33%
    if(head == nullptr)
    return nullptr;
    ListNode * scan = head;
    while(scan)
    {
    while(scan->next != nullptr && scan->val == scan->next->val) // 当前节点值与前一个节点值相等,跳过到下一个节点
    scan->next = scan->next->next;
    scan = scan->next; // 遍历整个链表
    }
    return head;

      // 第二种写法 beats 27.2%
      /*
        if(head == nullptr)
            return nullptr;
       ListNode * scan = head;
       while(scan && scan->next)
       {
           if(scan->val == scan->next->val)
                scan->next = scan->next->next;  // 与前一个节点重复则检查下下个节点
           else
                scan = scan->next;             // 不重复则依次遍历
       }
       return head;
       */

Log in to reply
 

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