{"id":5661,"date":"2019-09-30T09:36:34","date_gmt":"2019-09-30T16:36:34","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=5661"},"modified":"2019-09-30T09:38:27","modified_gmt":"2019-09-30T16:38:27","slug":"leetcode-83-remove-duplicates-from-sorted-list","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/list\/leetcode-83-remove-duplicates-from-sorted-list\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 83. Remove Duplicates from Sorted List"},"content":{"rendered":"\n<p>Given a sorted linked list, delete all duplicates such that each element appear only&nbsp;<em>once<\/em>.<\/p>\n\n\n\n<p><strong>Example 1:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> 1-&gt;1-&gt;2\n<strong>Output:<\/strong> 1-&gt;2\n<\/pre>\n\n\n\n<p><strong>Example 2:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted;crayon:false\"><strong>Input:<\/strong> 1-&gt;1-&gt;2-&gt;3-&gt;3\n<strong>Output:<\/strong> 1-&gt;2-&gt;3<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h2>\n\n\n\n<p>Time complexity: O(n)<br>Space complexity: O(1)<\/p>\n\n\n\n<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">C++<\/h2>\n<div class=\"tabcontent\">\n\n<pre lang=\"C++\">\/\/ Author: Huahua\nclass Solution {\npublic:\n  ListNode *deleteDuplicates(ListNode *head) {        \n    if (!head) return head;\n    ListNode d(0);\n    ListNode* t = &d;\n    t->next = head;\n    while (head) {\n      while (head && head->val == t->next->val) head = head->next;\n      t->next->next = head;\n      t = t->next;\n    }\n    return d.next;\n  }\n};\n<\/pre>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Given a sorted linked list, delete all duplicates such that each element appear only&nbsp;once. Example 1: Input: 1-&gt;1-&gt;2 Output: 1-&gt;2 Example 2: Input: 1-&gt;1-&gt;2-&gt;3-&gt;3 Output:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50],"tags":[333,222,83],"class_list":["post-5661","post","type-post","status-publish","format-standard","hentry","category-list","tag-duplicate","tag-easy","tag-list","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=5661"}],"version-history":[{"count":3,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5661\/revisions"}],"predecessor-version":[{"id":5664,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/5661\/revisions\/5664"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=5661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=5661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=5661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}