<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sherlock Chiou on Medium]]></title>
        <description><![CDATA[Stories by Sherlock Chiou on Medium]]></description>
        <link>https://medium.com/@sherlock-chiou?source=rss-c57535d15d42------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8qt3pGeYvn7fI0M_</url>
            <title>Stories by Sherlock Chiou on Medium</title>
            <link>https://medium.com/@sherlock-chiou?source=rss-c57535d15d42------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:28:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sherlock-chiou/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[LeetCode]89. Gray Code(Medium)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-89-gray-code-medium-b7ddc35e610?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7ddc35e610</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Fri, 19 Mar 2021 01:36:16 GMT</pubDate>
            <atom:updated>2021-03-19T01:36:16.104Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>The gray code is a binary numeral system where two successive values differ in <strong>only one bit</strong>.</blockquote><blockquote>Given an integer n representing the total number of bits in the code, return <strong><em>any</em></strong><em> sequence of gray code</em>.</blockquote><blockquote>A gray code sequence must begin with 0.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> n = 2<br><strong>Output:</strong> [0,1,3,2]<br><strong>Explanation:</strong><br>00 - 0<br>01 - 1<br>11 - 3<br>10 - 2<br>[0,2,3,1] is also a valid gray code sequence.<br>00 - 0<br>10 - 2<br>11 - 3<br>01 - 1</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/843eebc29d73b447d72797794a60e928/href">https://medium.com/media/843eebc29d73b447d72797794a60e928/href</a></iframe><h3>Solution 1:</h3><blockquote>Time complexity O(2^n). Each time we need to add 1 to the head of the numbers in binary. And the sequence starts from the tail of result List.</blockquote><pre><strong>Input:</strong> n = 1<br><strong>Explanation:</strong><br>0 - 0<br>------<br>1 - 1</pre><pre><strong>Input:</strong> n = 2<br><strong>Explanation:</strong><br>00 - 0<br>01 - 1<br>-------<br>11 - 3<br>10 - 2</pre><pre><strong>Input:</strong> n = 3<br><strong>Explanation:</strong><br>000 - 0<br>001 - 1<br>011 - 3<br>010 - 2<br>--------<br>110 - 6<br>111 - 7<br>101 - 5<br>100 - 4</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7ddc35e610" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]83. Remove Duplicates from Sorted List(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-83-remove-duplicates-from-sorted-list-easy-990053e49504?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/990053e49504</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Thu, 18 Mar 2021 01:02:02 GMT</pubDate>
            <atom:updated>2021-03-18T01:02:02.910Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>Given the head of a sorted linked list, <em>delete all duplicates such that each element appears only once</em>. Return <em>the linked list </em><strong><em>sorted</em></strong><em> as well</em>.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> head = [1,1,2,3,3]<br><strong>Output:</strong> [1,2,3]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3aa8cf85610830972456d29b906df20/href">https://medium.com/media/a3aa8cf85610830972456d29b906df20/href</a></iframe><h3>Solution 1:</h3><blockquote><em>Time complexity O(N). We would need both prev and curNode. If prev’s value is equivalent to curNode’s value, set prev.next to curNode.next. Otherwise, move prev to prev.next.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=990053e49504" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]70. Climbing Stairs(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-70-climbing-stairs-easy-716df4515470?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/716df4515470</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Wed, 17 Mar 2021 01:25:39 GMT</pubDate>
            <atom:updated>2021-03-17T01:25:39.298Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>You are climbing a staircase. It takes n steps to reach the top.</blockquote><blockquote>Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> n = 2<br><strong>Output:</strong> 2<br><strong>Explanation:</strong> There are two ways to climb to the top.<br>1. 1 step + 1 step<br>2. 2 steps</pre><h3>Example 2:</h3><pre><strong>Input:</strong> n = 3<br><strong>Output:</strong> 3<br><strong>Explanation:</strong> There are three ways to climb to the top.<br>1. 1 step + 1 step + 1 step<br>2. 1 step + 2 steps<br>3. 2 steps + 1 step</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61a2217ce665baf8e734639d0a75b1f8/href">https://medium.com/media/61a2217ce665baf8e734639d0a75b1f8/href</a></iframe><h3>Solution 1:</h3><blockquote>Time complexity O(N²). Find the combination of each solution.</blockquote><h3>Solution 2:</h3><blockquote>Time complexity O(N). Dynamic Programming. The n stair can be reached from either n-1 stair with 1 step, or n-2 stair with 2 step. So the total possible steps would be equivalent to solution[n-1] plus soultion[n-2]. The base cases: one stair for one step, two stair for two possible steps.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=716df4515470" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]67. Add Binary(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-67-add-binary-easy-e0155e1b4103?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0155e1b4103</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 03:01:55 GMT</pubDate>
            <atom:updated>2021-03-16T03:01:55.887Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>Given two binary strings a and b, return <em>their sum as a binary string</em>.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> a = &quot;11&quot;, b = &quot;1&quot;<br><strong>Output:</strong> &quot;100&quot;</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce1c6a6de91e798ec80c27c912f8078e/href">https://medium.com/media/ce1c6a6de91e798ec80c27c912f8078e/href</a></iframe><h3>Solution 1:</h3><p><em>Time complexity O(max(len(A), len(B))). Python use ord() to change character into ASCII code. And str() would convert int to string. If you want to use chr(), change the str() part to chr(bitsum%2 + ord(‘0’)).</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0155e1b4103" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]53. Maximum Subarray(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-53-maximum-subarray-easy-1e078a97fea3?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e078a97fea3</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Mon, 15 Mar 2021 01:56:58 GMT</pubDate>
            <atom:updated>2021-03-15T01:56:58.254Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return <em>its sum</em>.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> nums = [-2,1,-3,4,-1,2,1,-5,4]<br><strong>Output:</strong> 6<br><strong>Explanation:</strong> [4,-1,2,1] has the largest sum = 6.</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/851b82706c8a637a0f3af36a587f0d65/href">https://medium.com/media/851b82706c8a637a0f3af36a587f0d65/href</a></iframe><h3>Solution 1:</h3><blockquote>Dynamic Programming. Time complexity O(N), N= Length of nums. In Dynamic Proggramming, <strong>solution of i+1</strong> step is close related to the <strong>solution of i step</strong> and <strong>i+1 value</strong>. In this problem, we have to consider if i+1 value is the new head of a contiguous subarray. The head of a contiguous subarray would fulfill the requirement that its value <strong>x</strong> would greater than the summation of <strong>x </strong>and tempMax. And each time, we have to check if the updated tempMax is greater than the res value.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e078a97fea3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]35. Search Insert Position(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-35-search-insert-position-easy-84d6dbd50ef3?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/84d6dbd50ef3</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Fri, 12 Mar 2021 02:14:55 GMT</pubDate>
            <atom:updated>2021-03-12T02:14:55.275Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> nums = [1,3,5,6], target = 5<br><strong>Output:</strong> 2</pre><h3>Example 2:</h3><pre><strong>Input:</strong> nums = [1,3,5,6], target = 2<br><strong>Output:</strong> 1</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbe40c3d76a04e92b524c6c9e7f139b5/href">https://medium.com/media/fbe40c3d76a04e92b524c6c9e7f139b5/href</a></iframe><h3>Solution 1:</h3><blockquote><em>Linear Search. Time complexity O(N), N= Length of nums.</em></blockquote><h3>Solution 2:</h3><blockquote><em>Binary Search. Time complexity O(log(N)), N= Length of nums. When the nums did not contain the target number. In the end of the while loop, leftIndex would equal rightIndex. And if nums[midIndex] &gt; target, the index of target should be midIndex. Otherwise, the the index of target should be midIndex+1.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84d6dbd50ef3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]26. Remove Duplicates from Sorted Array(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-26-remove-duplicates-from-sorted-array-easy-6cc610495283?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cc610495283</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Thu, 11 Mar 2021 02:13:39 GMT</pubDate>
            <atom:updated>2021-03-11T02:13:39.823Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>Given a sorted array <em>nums</em>, remove the duplicates <a href="https://en.wikipedia.org/wiki/In-place_algorithm"><strong>in-place</strong></a> such that each element appears only <em>once</em> and returns the new length.</blockquote><blockquote>Do not allocate extra space for another array, you must do this by <strong>modifying the input array </strong><a href="https://en.wikipedia.org/wiki/In-place_algorithm"><strong>in-place</strong></a> with O(1) extra memory.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> nums = [1,1,2]<br><strong>Output:</strong> 2, nums = [1,2]<br><strong>Explanation:</strong> Your function should return length = <strong>2</strong>, with the first two elements of <em>nums</em> being <strong>1</strong> and <strong>2</strong> respectively. It doesn&#39;t matter what you leave beyond the returned length.</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cadc4076a363f28ff6056c10d3c19ddc/href">https://medium.com/media/cadc4076a363f28ff6056c10d3c19ddc/href</a></iframe><h3>Solution 1:</h3><blockquote>Time complexity O(N), N= Length of nums. leftIndex helps us to keep track of the last unique number we get. When nums[leftIndex] == nums[rightIndex], we would discard this number, using pop(). Otherwise, plus 1 to both leftIndex and rightIndex.</blockquote><h3>Solution 2:</h3><blockquote>Time complexity O(N), N= Length of nums. leftIndex helps us to keep track of the last unique number we get. When nums[leftIndex] != nums[rightIndex], we would assign nums[rightIndex] to nums[leftIndex]. And plus 1 to both leftIndex and rightIndex. Otherwise, plus one to rightIndex.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cc610495283" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]21. Merge Two Sorted Lists(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-21-merge-two-sorted-lists-easy-c4b4582b5cfe?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4b4582b5cfe</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Wed, 10 Mar 2021 03:12:08 GMT</pubDate>
            <atom:updated>2021-03-10T03:12:08.398Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote>Merge two sorted linked lists and return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.</blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> l1 = [1,2,4], l2 = [1,3,4]<br><strong>Output:</strong> [1,1,2,3,4,4]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/589f7b83424557be21f81c70507ad8f5/href">https://medium.com/media/589f7b83424557be21f81c70507ad8f5/href</a></iframe><h3>Solution 1:</h3><blockquote><em>Time complexity O(A+B), A = Number of nodes in L1, B= Number of nodes in L2. The prevNode is used to keep track of the previous Node. Because node in linked list only have the information of the node value, and next node’s memory address. Mind that Python would pass by reference, when assigning object.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4b4582b5cfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]15. Longest Common Prefix(Medium)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-15-longest-common-prefix-medium-4f3d0dc7e10?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f3d0dc7e10</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Sat, 20 Feb 2021 02:31:59 GMT</pubDate>
            <atom:updated>2021-03-05T07:25:00.766Z</atom:updated>
            <content:encoded><![CDATA[<h3>[LeetCode]15. 3Sum(Medium)</h3><h3>Description:</h3><blockquote>Given an array nums of <em>n</em> integers, are there elements <em>a</em>, <em>b</em>, <em>c</em> in nums such that <em>a</em> + <em>b</em> + <em>c</em> = 0? Find all unique triplets in the array which gives the sum of zero.</blockquote><blockquote>Notice that the solution set must not contain duplicate triplets.</blockquote><h4><strong>Example 1:</strong></h4><pre><strong>Input:</strong> nums = [-1,0,1,2,-1,-4]<br><strong>Output:</strong> [[-1,-1,2],[-1,0,1]]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4084f0646e7c8bbe5383b09e51562584/href">https://medium.com/media/4084f0646e7c8bbe5383b09e51562584/href</a></iframe><h4>Solution 1:</h4><blockquote><em>Time complexity O(N³)，O(N*N-1*N-2)</em></blockquote><h4>Solution 2:</h4><blockquote><em>Time complexity O(N²)，</em><strong>Two pointer method</strong><em>. After we sort the nums List, nums would be like [-4, -1, -1 , 0, 1, 2]. In the beginning, nums[index] = -4, nums[secondIndex] = -1, and nums[thirdIndex] = 2. We would need complement 4(a+b+c = 0), but the sum of this pair is 3. Since the largest value we can use is 2, so we would let secondIndex plus 1. In orger to generate larger pair sum and vice versa. <br>How do we avoid the duplicate answer? By skipping nums[index] == nums[index-1]. And when the pair value equals the complement, we would adjust both the secondIndex and thirdIndex, until they both get different value than the pair we get. Hence, we can get the next pair whose pair value equals the complement.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f3d0dc7e10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[LeetCode]14. Longest Common Prefix(Easy)]]></title>
            <link>https://sherlock-chiou.medium.com/leetcode-14-longest-common-prefix-easy-a1198f8ce4c?source=rss-c57535d15d42------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1198f8ce4c</guid>
            <dc:creator><![CDATA[Sherlock Chiou]]></dc:creator>
            <pubDate>Fri, 19 Feb 2021 03:49:36 GMT</pubDate>
            <atom:updated>2021-02-19T03:49:36.203Z</atom:updated>
            <content:encoded><![CDATA[<h3>Description:</h3><blockquote><em>Write a function to find the longest common prefix string amongst an array of strings.</em></blockquote><blockquote><em>If there is no common prefix, return an empty string </em><em>&quot;&quot;.</em></blockquote><h3>Example 1:</h3><pre><strong>Input:</strong> strs = [&quot;flower&quot;,&quot;flow&quot;,&quot;flight&quot;]<br><strong>Output:</strong> &quot;fl&quot;</pre><h3>Example 2:</h3><pre><strong>Input:</strong> strs = [&quot;dog&quot;,&quot;racecar&quot;,&quot;car&quot;]<br><strong>Output:</strong> &quot;&quot;<br><strong>Explanation:</strong> There is no common prefix among the input strings.</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d506b3f3617f99f50de845bc45c5f83b/href">https://medium.com/media/d506b3f3617f99f50de845bc45c5f83b/href</a></iframe><h4>Solution 1:</h4><blockquote>Time complexity O(S)，S stands for the strs List’s total number of characters . The worst case would be the strings in the List are all the same.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1198f8ce4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>