{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "fb80bffeb84e4af98e68afa1b7bfe0e4",
  "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": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class ListNode(object):\n\tdef __init__(self, x):\n\t\tself.val = x\n\t\tself.next = None\nclass LinkList:\n\tdef __init__(self):\n\t\tself.head=None\n\tdef initList(self, data):\n\t\tself.head = ListNode(data[0])\n\t\tr=self.head\n\t\tp = self.head\n\t\tfor i in data[1:]:\n\t\t\tnode = ListNode(i)\n\t\t\tp.next = node\n\t\t\tp = p.next\n\t\treturn r\n\tdef\tconvert_list(self,head):\n\t\tret = []\n\t\tif head == None:\n\t\t\treturn\n\t\tnode = head\n\t\twhile node != None:\n\t\t\tret.append(node.val)\n\t\t\tnode = node.next\n\t\treturn ret\nclass Solution(object):\n\tdef deleteDuplicates(self, head):\n\t\t\"\"\"\n\t\t:type head: ListNode\n\t\t:rtype: ListNode\n\t\t\"\"\"\n\t\tnewnodehead = None\n\t\tnewnode = None\n\t\tnode = head\n\t\twhile node:\n\t\t\tlastval = node.val\n\t\t\tif node.next and node.next.val == lastval:\n\t\t\t\twhile node and node.val == lastval:\n\t\t\t\t\tnode=node.next\n\t\t\t\tcontinue\n\t\t\tif not newnodehead:\n\t\t\t\tnewnode=ListNode(node.val)\n\t\t\t\tnewnodehead=newnode\n\t\t\telse:\n\t\t\t\tnewnode.next=ListNode(node.val)\n\t\t\t\tnewnode=newnode.next\n\t\t\tnode = node.next\n\t\treturn newnodehead\n# %%\nl = LinkList()\nlist1 = [1,2,3,3,4,4,5]\nl1 = l.initList(list1)\ns = Solution()\nprint(l.convert_list(s.deleteDuplicates(l1)))",
    "language": "python"
  },
  "node_id": "dailycode-00212162ec234e81a8f9274d7c9a85d2",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600470128"
}