<?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 Ed on Medium]]></title>
        <description><![CDATA[Stories by Ed on Medium]]></description>
        <link>https://medium.com/@edwardllookk?source=rss-55dd4d355bea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TatYec6qVWnRnjSeUb57sw.jpeg</url>
            <title>Stories by Ed on Medium</title>
            <link>https://medium.com/@edwardllookk?source=rss-55dd4d355bea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:08:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@edwardllookk/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[Day 95: Reverse Words in a String II]]></title>
            <link>https://medium.com/@edwardllookk/day-95-reverse-words-in-a-string-ii-c67342101746?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/c67342101746</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[reverse-string]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Thu, 02 May 2019 04:14:04 GMT</pubDate>
            <atom:updated>2019-05-02T04:14:04.061Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/reverse-words-in-a-string-ii/">LeetCode 186. Reverse Words in a String II</a></p><pre>class Solution {<br>public:<br>    void reverseWords(vector&lt;char&gt;&amp; str) {<br>        reverse(str.begin(), str.end());<br>        int i = 0, j = 0;<br>        while(i &lt; str.size()) {<br>            int j = i;<br>            while (j &lt; str.size() &amp;&amp; str[j] != &#39; &#39;)<br>            {<br>                 ++j;<br>            }            <br>            reverse(str.begin()+i, str.begin()+j);<br>            i = j + 1;<br>        }<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c67342101746" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 94: Ransom Note]]></title>
            <link>https://medium.com/@edwardllookk/day-94-ransom-note-4f51d26a890d?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f51d26a890d</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[cxx]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Wed, 01 May 2019 04:45:54 GMT</pubDate>
            <atom:updated>2019-05-01T04:45:54.358Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/ransom-note/">LeetCode 383. Ransom Note</a></p><pre>class Solution {<br>public:<br>    bool canConstruct(string ransomNote, string magazine) {<br>        unordered_map&lt;char, int&gt; lookup;   <br>        <br>        for (char const &amp; c: magazine)<br>        {<br>            lookup[c]++;<br>        }<br>        <br>        for (int i = 0; i &lt; ransomNote.length(); i++)<br>        {<br>            if (--lookup[ransomNote[i]] &lt; 0)<br>            {<br>                return false;<br>            }<br>        }<br>        <br>        return true;<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f51d26a890d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 93: Length of Last Word]]></title>
            <link>https://medium.com/@edwardllookk/day-93-length-of-last-word-2ed3d87a5975?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ed3d87a5975</guid>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[length-of-last-word]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Tue, 30 Apr 2019 04:02:38 GMT</pubDate>
            <atom:updated>2019-04-30T04:02:38.509Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/length-of-last-word/">LeetCode 58. Length of Last Word</a></p><p>Using istringstream</p><pre>class Solution {<br>public:<br>    int lengthOfLastWord(string s) {<br>        int res = 0;<br>        <br>        istringstream iss(s);<br>        string last = &quot;&quot;;<br>        <br>        while (iss &gt;&gt; last)<br>        {<br>            res = last.length();<br>        }<br>        <br>        return res;<br>    }<br>};</pre><p>Count backward from the tail:</p><pre>class Solution {<br>public:<br>    int lengthOfLastWord(string s) {<br>        int res = 0;<br>        int tail = s.length() - 1;<br>        <br>        while(s[tail] == &#39; &#39; &amp;&amp; tail &gt;= 0)<br>        {<br>            tail--;<br>        }<br>        <br>        while(s[tail] != &#39; &#39; &amp;&amp; tail &gt;= 0)<br>        {<br>            tail--;<br>            res++;<br>        }<br>        <br>        return res;<br>    }<br>};</pre><ol><li>clean up all the empty char in the tail.</li><li>count backward and hit the first empty char. The length is the result.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ed3d87a5975" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 92: Bulls and Cows]]></title>
            <link>https://medium.com/@edwardllookk/day-92-bulls-and-cows-a50790f667ef?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/a50790f667ef</guid>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[bulls-and-cows]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 05:01:23 GMT</pubDate>
            <atom:updated>2019-04-29T05:01:23.998Z</atom:updated>
            <content:encoded><![CDATA[<p>299. Bulls and Cows</p><p>Vector-based solution:</p><pre>class Solution {<br>public:<br>    string getHint(string secret, string guess) {<br>        int bulls = 0;<br>        int cows = 0;<br>        vector&lt;int&gt; s_record(10, 0);<br>        vector&lt;int&gt; g_record(10, 0);<br>        for (int i = 0; i &lt; secret.size(); ++i) {<br>            char c1 = secret[i]; char c2 = guess[i];<br>            if (c1 == c2) {<br>                ++bulls; <br>            } else {<br>                ++s_record[c1-&#39;0&#39;];<br>                ++g_record[c2-&#39;0&#39;];<br>            }<br>        }<br>        <br>        for (int i = 0; i &lt; s_record.size(); ++i) {<br>            cows += min(s_record[i], g_record[i]);<br>        }<br>        return to_string(bulls) + &#39;A&#39; + to_string(cows) + &#39;B&#39;;<br>        <br>    }<br>};</pre><p>Unordered_map solution:</p><pre>class Solution {<br>public:<br>    string getHint(string secret, string guess) {<br>        unordered_map&lt;char, int&gt; s_map;<br>        unordered_map&lt;char, int&gt; g_map;<br>        int n = secret.size();<br>        int A = 0, B = 0;<br>        for (int i = 0; i &lt; n; i++)<br>        {<br>            char s = secret[i], g = guess[i];<br>            if (s == g)<br>                A++;<br>            else<br>            {<br>                (s_map[g] &gt; 0) ? s_map[g]--, B++ : g_map[g]++;<br>                (g_map[s] &gt; 0) ? g_map[s]--, B++ : s_map[s]++; <br>            }<br>        }<br>        return to_string(A) + &quot;A&quot; + to_string(B) + &quot;B&quot;;<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a50790f667ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 91: Search Insert Position]]></title>
            <link>https://medium.com/@edwardllookk/day-91-search-insert-position-2519bd0b38e8?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/2519bd0b38e8</guid>
            <category><![CDATA[sorted-array]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[insert-number]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Tue, 23 Apr 2019 06:40:34 GMT</pubDate>
            <atom:updated>2019-04-23T06:40:34.464Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/search-insert-position/">LeetCode 35. Search Insert Position</a></p><pre>class Solution {<br>public:<br>    int searchInsert(vector&lt;int&gt;&amp; nums, int target) {<br>        int left=0;<br>        int right=nums.size()-1;<br>        int mid = 0;<br>        while(left&lt;=right){<br>            mid = left + (right - left)/2;<br>            if(target &gt; nums[mid])<br>            {<br>                left = mid + 1;<br>            }<br>            else if (target == nums[mid])<br>            {<br>                return mid;<br>            }<br>            else<br>            {<br>                right = mid - 1;<br>            }<br>        }<br>        return left;<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2519bd0b38e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 90: Reverse String]]></title>
            <link>https://medium.com/@edwardllookk/day-90-reverse-string-d78678954f17?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/d78678954f17</guid>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[reverse-string]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Mon, 22 Apr 2019 05:08:34 GMT</pubDate>
            <atom:updated>2019-04-22T05:08:34.591Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/reverse-string/">LeetCode 344. Reverse String</a></p><pre>class Solution {<br>public:<br>    void reverseString(vector&lt;char&gt;&amp; s) {<br>        int l = 0, r = s.size() - 1;<br>        <br>        while(l &lt;= r)<br>        {<br>            swap(s[l], s[r]);<br>            l++;<br>            r--;<br>        }<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d78678954f17" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 89: Find the Celebrity]]></title>
            <link>https://medium.com/@edwardllookk/day-89-find-the-celebrity-f5ba6800929a?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5ba6800929a</guid>
            <category><![CDATA[find-the-celebrity]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[cxx]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Sat, 20 Apr 2019 04:04:15 GMT</pubDate>
            <atom:updated>2019-04-20T04:04:15.950Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/find-the-celebrity/">LeetCode 277. Find the Celebrity</a></p><pre>class Solution {<br>public:<br>    int lengthOfLongestSubstring(string s) {<br>        int maxLen = 0;<br>        unordered_set&lt;char&gt; lookup;<br>        <br>        int i = 0, j = 0;<br>        <br>        while (j &lt; s.length())<br>        {<br>            if (!lookup.count(s[j]))<br>            {<br>                lookup.insert(s[j]);<br>                j++;<br>                maxLen = max(maxLen, j - i);<br>            }<br>            else<br>            {<br>                lookup.erase(s[i]);<br>                i++;<br>            }<br>        }<br>        return maxLen;<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5ba6800929a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 88: Longest Substring Without Repeating Characters]]></title>
            <link>https://medium.com/@edwardllookk/day-88-longest-substring-without-repeating-characters-e5160f88f95c?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5160f88f95c</guid>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[substring]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Fri, 19 Apr 2019 04:05:36 GMT</pubDate>
            <atom:updated>2019-04-19T04:05:36.082Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/longest-substring-without-repeating-characters/">LeetCode 3. Longest Substring Without Repeating Characters</a></p><pre>class Solution {<br>public:<br>    int lengthOfLongestSubstring(string s) {<br>        int maxLen = 0;<br>        unordered_set&lt;char&gt; lookup;<br>        <br>        int i = 0, j = 0;<br>        <br>        while (j &lt; s.length())<br>        {<br>            if (!lookup.count(s[j]))<br>            {<br>                lookup.insert(s[j]);<br>                j++;<br>                maxLen = max(maxLen, j - i);<br>            }<br>            else<br>            {<br>                lookup.erase(s[i]);<br>                i++;<br>            }<br>        }<br>        return maxLen;<br>    }<br>};</pre><p>Two pointers solution:</p><ol><li>Fast pointer j and slow pointer both start at index 0 and maxLen is set to 0 at the beginning.</li><li>We move the fast pointer j first, if char s[j] has not been seen in the hash set lookup yet, then this char will be added into the lookup. The maxLen will be updated depending on if the current length j-i is larger than the maxLen itself.</li><li>However, if the character s[j] has been seen in the lookup container, this means that one repeated character occurs. The char s[i] will be removed and the index i will increase by 1. With this move, we are hoping for a new starting point of the potential the longest substring.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5160f88f95c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 87: Single Number]]></title>
            <link>https://medium.com/@edwardllookk/day-87-single-number-513383decc0f?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/513383decc0f</guid>
            <category><![CDATA[single-number]]></category>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 03:19:20 GMT</pubDate>
            <atom:updated>2019-04-18T03:19:20.967Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/single-number/">LeetCode 136. Single Number</a></p><pre>class Solution {<br>public:<br>    int singleNumber(vector&lt;int&gt;&amp; nums) {<br>        sort(nums.begin(), nums.end());<br>        int next = 1;<br>        int cur = 0;<br>        while (next &lt; nums.size())<br>        {<br>            if (nums[next] != nums[cur])<br>            {<br>                return nums[cur];<br>            }<br>            next += 2;<br>            cur += 2;<br>        }<br>        <br>        return nums[nums.size() - 1];<br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=513383decc0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Day 86: 
Remove Duplicates from Sorted List II]]></title>
            <link>https://medium.com/@edwardllookk/day-86-remove-duplicates-from-sorted-list-ii-42d0e8287391?source=rss-55dd4d355bea------2</link>
            <guid isPermaLink="false">https://medium.com/p/42d0e8287391</guid>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[cxx]]></category>
            <category><![CDATA[linked-lists]]></category>
            <category><![CDATA[remove-duplicates]]></category>
            <dc:creator><![CDATA[Ed]]></dc:creator>
            <pubDate>Wed, 17 Apr 2019 02:58:15 GMT</pubDate>
            <atom:updated>2019-04-17T02:58:15.681Z</atom:updated>
            <content:encoded><![CDATA[<h3>Day 86: <br>Remove Duplicates from Sorted List II</h3><p><a href="https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/">LeetCode 82. Remove Duplicates from Sorted List II</a></p><pre>class Solution {<br>public:<br>    ListNode* deleteDuplicates(ListNode* head) {<br>        if (!head) return head;<br>        <br>        ListNode* dummy = new ListNode(0);<br>        dummy -&gt; next = head;<br>        ListNode* prev = dummy;<br>        long long record = LLONG_MAX;<br>        while (head) {<br>            if (head-&gt;next &amp;&amp; head-&gt;next-&gt;val == head-&gt;val) {<br>                record = head-&gt;val;<br>                head = head-&gt;next-&gt;next;<br>                prev-&gt;next = head;<br>            }<br>            else if (head-&gt;val == record) {<br>                head = head-&gt;next;<br>                prev-&gt;next = head;<br>            }<br>            else {<br>                head = head-&gt;next;<br>                prev = prev-&gt;next;<br>            }<br>        }</pre><pre>return dummy -&gt; next;<br>        <br>    }<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42d0e8287391" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>