solution.json 3.1 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "d880c4799a52441f9d30628b196315d0",
  "keywords": "链表,双指针",
  "title": "删除排序链表中的重复元素 II",
  "desc": [
    {
      "content": "\n<p>存在一个按升序排列的链表,给你这个链表的头节点 <code>head</code> ,请你删除链表中所有存在数字重复情况的节点,只保留原始链表中 <strong>没有重复出现</strong><em> </em>的数字。</p><p>返回同样按升序排列的结果链表。</p><p> </p><p><strong>示例 1:</strong></p><img alt=\"\" src=\"https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/images/linkedlist1.jpg\" style=\"width: 500px; height: 142px;\" /><pre><strong>输入:</strong>head = [1,2,3,3,4,4,5]<strong><br />输出:</strong>[1,2,5]</pre><p><strong>示例 2:</strong></p><img alt=\"\" src=\"https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/0000-0099/0082.Remove%20Duplicates%20from%20Sorted%20List%20II/images/linkedlist2.jpg\" style=\"width: 500px; height: 205px;\" /><pre><strong>输入:</strong>head = [1,1,1,2,3]<strong><br />输出:</strong>[2,3]</pre><p> </p><p><strong>提示:</strong></p><ul>\t<li>链表中节点数目在范围 <code>[0, 300]</code> 内</li>\t<li><code>-100 <= Node.val <= 100</code></li>\t<li>题目数据保证链表已经按升序排列</li></ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\n#include <stdlib.h>\nstruct ListNode\n{\n\tint val;\n\tstruct ListNode *next;\n};\nstruct ListNode *deleteDuplicates(struct ListNode *head)\n{\n\tstruct ListNode dummy;\n\tstruct ListNode *p, *q, *prev;\n\tprev = &dummy;\n\tdummy.next = head;\n\tp = q = head;\n\twhile (p != NULL)\n\t{\n\t\twhile (q != NULL && q->val == p->val)\n\t\t{\n\t\t\tq = q->next;\n\t\t}\n\t\tif (p->next == q)\n\t\t{\n\t\t\tprev = p;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprev->next = q;\n\t\t}\n\t\tp = q;\n\t}\n\treturn dummy.next;\n}\nint main(int argc, char **argv)\n{\n\tint i;\n\tstruct ListNode *head = NULL;\n\tstruct ListNode *prev = NULL;\n\tstruct ListNode *p;\n\tfor (i = 0; i < argc - 1; i++)\n\t{\n\t\tp = malloc(sizeof(*p));\n\t\tp->val = atoi(argv[i + 1]);\n\t\tp->next = NULL;\n\t\tif (head == NULL)\n\t\t{\n\t\t\thead = p;\n\t\t\tprev = head;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tprev->next = p;\n\t\t\tprev = p;\n\t\t}\n\t}\n\tp = deleteDuplicates(head);\n\twhile (p != NULL)\n\t{\n\t\tprintf(\"%d \", p->val);\n\t\tp = p->next;\n\t}\n\tprintf(\"\\n\");\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-c93700cb5c094f74a66dfef7fa2ab6b3",
  "license": "csdn.net",
  "created_at": 1637894158,
  "topic_link": "https://bbs.csdn.net/topics/600470128"
}