<?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 Chia-Han, Chung 鍾家涵 on Medium]]></title>
        <description><![CDATA[Stories by Chia-Han, Chung 鍾家涵 on Medium]]></description>
        <link>https://medium.com/@chiahan.tw?source=rss-84874720db4e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ci00QHMPX0mtvj91.</url>
            <title>Stories by Chia-Han, Chung 鍾家涵 on Medium</title>
            <link>https://medium.com/@chiahan.tw?source=rss-84874720db4e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 10:55:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chiahan.tw/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[Heptabase 筆記軟體 — 金魚腦救星]]></title>
            <link>https://medium.com/@chiahan.tw/heptabase-%E7%AD%86%E8%A8%98%E8%BB%9F%E9%AB%94-%E9%87%91%E9%AD%9A%E8%85%A6%E6%95%91%E6%98%9F-97c00bfc1724?source=rss-84874720db4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/97c00bfc1724</guid>
            <category><![CDATA[heptabase]]></category>
            <dc:creator><![CDATA[Chia-Han, Chung 鍾家涵]]></dc:creator>
            <pubDate>Sun, 24 Nov 2024 03:52:25 GMT</pubDate>
            <atom:updated>2024-11-24T03:58:26.541Z</atom:updated>
            <content:encoded><![CDATA[<h3>Heptabase 筆記軟體 — 金魚腦救星</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pdB3G24G8X7booAt" /></figure><h3>特色：</h3><ol><li>UI 直覺，無痛上手</li><li>讓人專注在編輯內容，不會浪費時間在排版</li><li>白板功能，可以同時攤開多張筆記卡片，把關係線畫出來，像偵探辦案，節省大腦用量，拯救金魚腦</li><li>支援電腦、手機、 iPad、網頁版，隨時隨地更新筆記</li><li>輸出格式為 Markdown，匯入的圖片和檔案皆有備份</li><li>搜尋功能回應快速</li></ol><h3>適合對象：</h3><p>上班族、研究生、學生、作家…等，需要搜集素材、準備考試、寫文章，有筆記軟體需求的人</p><h3>馬上下載試用：</h3><p>點以下連結使用我的邀請碼，獲得7天免費試用，訂閱折扣 $5 美元</p><p>（月訂閱 $11.99 美元、年訂閱$ 107.88 美元）</p><p><a href="https://join.heptabase.com/?invite-acc-id=ed061d6c-4896-4b0e-93f2-24a1246c4cd9">Heptabase | Referral</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97c00bfc1724" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leetcode 752. Open the Lock]]></title>
            <link>https://medium.com/@chiahan.tw/leetcode-752-open-the-lock-fab3ec388945?source=rss-84874720db4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fab3ec388945</guid>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[leetcode-medium]]></category>
            <category><![CDATA[fb]]></category>
            <dc:creator><![CDATA[Chia-Han, Chung 鍾家涵]]></dc:creator>
            <pubDate>Sun, 05 Apr 2020 13:43:01 GMT</pubDate>
            <atom:updated>2020-04-05T13:51:27.499Z</atom:updated>
            <content:encoded><![CDATA[<p>難度 <strong>Medium</strong></p><h4>題目</h4><ol><li>一個四位數的密碼鎖，每個輪盤由0~9組成</li><li>起始都從0000開始，給定一個target，轉到target鎖就能打開</li><li>需注意，如果轉到deadends裡的數字組合，鎖就會永遠打不開</li></ol><h4>目標</h4><ol><li>回傳最少要轉動幾次輪盤才能打開鎖</li><li>如果永遠開不了，回傳-1</li></ol><h4>範例 1 打得開的鎖</h4><pre><strong>Input:</strong> deadends = [], <br>target = &quot;0001&quot;<br><strong>Output:</strong> 1<br><strong>Explanation: </strong>起始位置為0000，只要轉動一次第四個輪盤讓它指到1，就能到target。</pre><h4>範例 2 打不開的鎖</h4><pre><strong>Input:</strong> deadends = [&quot;8887&quot;,&quot;8889&quot;,&quot;8878&quot;,&quot;8898&quot;,&quot;8788&quot;,&quot;8988&quot;,&quot;7888&quot;,&quot;9888&quot;], <br>target = &quot;8888&quot;<br><strong>Output:</strong> -1<br><strong>Explanation: </strong>轉到8888之前必經過deadends裡的組合，所以鎖永遠打不開。</pre><h4>想法</h4><p>將問題轉化為graph，用BFS去搜尋最短路徑<br>每個數字組合都是一個Node，和它轉動一次可以產生的結果由edge相連</p><p>下圖舉起始點0000為例，第一個數字往上轉可到1000，往下轉可到9000，以此類推共有8種組合。</p><figure><img alt="0000轉一格可以到的數字組合總共8個" src="https://cdn-images-1.medium.com/max/664/1*ErjPuxUEMUizq0xDjGfAcQ.png" /></figure><p>用這種方法將所有的走法串起來組出一張大圖，採用BFS，當搜尋到target的Node時，經過的edge數即為最少轉動就能打開鎖的方法。</p><h4>程式碼</h4><p>psuedo code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75caad9efeda2658c66ec306c2485f05/href">https://medium.com/media/75caad9efeda2658c66ec306c2485f05/href</a></iframe><p>Java code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91bd6facb3aedd5b3f4d269ee9209dfa/href">https://medium.com/media/91bd6facb3aedd5b3f4d269ee9209dfa/href</a></iframe><h4>複雜度</h4><p>n: node數</p><p>Time: O(n)<br>每個輪盤最多只有0~9這10種可能，全檢查過為10*10*10*10=10⁴</p><p>Space: O(n)<br>檢查過的組合就不會再檢查一次了，故queue中的node數必小於10⁴個</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fab3ec388945" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chain of Responsibility]]></title>
            <link>https://medium.com/@chiahan.tw/chain-of-responsibility-7ea924e816e3?source=rss-84874720db4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ea924e816e3</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Chia-Han, Chung 鍾家涵]]></dc:creator>
            <pubDate>Sun, 07 Jan 2018 14:07:26 GMT</pubDate>
            <atom:updated>2018-01-14T10:40:17.366Z</atom:updated>
            <content:encoded><![CDATA[<h4>Behavioral Pattern</h4><h4>Intro</h4><p>Chain of responsibility is a behavioral design pattern. When you have multiple handlers that can handle a request and the exact handler who handles the request is unknown. This pattern can decouple the sender of the request and the handlers as well as the decouple the handlers from each other. The chain of the Handlers can be formed dynamically formed in Client or the base class of Handlers.</p><h4>Structure</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ZVmUATJio8dV1VF8BV2qQ.png" /><figcaption>UML of Chain of Responsibility Pattern</figcaption></figure><h4>Participants</h4><ol><li>Handler<br>- Defines the interface for handling requests<br>- Implement the successor link (optional)</li><li>ConcreteHandler<br>- Handles requests it is responsible for<br>- Can access its successor<br>- If can handle request, it does so; else forwards the request to its successor</li><li>Client<br>- Initiates the request to a ConcreteHandler object on the chain</li></ol><h4>Code Example</h4><p>This is an example of a leave system.<br>The approval chain can be formed dynamically according to the applicant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvUlefi-awDDqZOSQxQm9g.png" /><figcaption>The structure of the chain that formed in this example is on the top. The UML diagram of this example is on the bottom.</figcaption></figure><p>Handler</p><pre>abstract class Staff {<br>    protected Staff nextStaff;<br>    protected String name;<br>    <br>    public Staff(String name) {<br>        this.name = name;<br>    }</pre><pre>    public void setNextStaff(Staff nextStaff) {<br>        this.nextStaff = nextStaff;<br>    }</pre><pre>    public void receiveRequest(Request req) {<br>        handle(req);<br>        if (nextStaff != null &amp;&amp; req.approved != true) {<br>            nextStaff.receiveRequest(req);<br>        }<br>    };</pre><pre>    protected abstract void handle(Request req);<br>}</pre><p>Concrete Handlers</p><pre>public class TeamLeader extends Staff {<br>    public TeamLeader(String name) {<br>        super(name);<br>    }</pre><pre>    @Override<br>    public void handle(Request req) {<br>        if (req.days &lt; 3) {<br>            System.out.println(&quot;Team Leader &quot; + this.name <br>                               + &quot; approved!&quot;);<br>            req.setApproved();<br>        } else {<br>            System.out.println(&quot;Team Leader &quot; + this.name <br>                               + &quot; signed.&quot;);<br>        }<br>    }<br>}</pre><pre>public class Manager extends Staff {<br>    public Manager(String name) {<br>        super(name);<br>    }</pre><pre>    @Override<br>    public void handle(Request req) {<br>        if (req.days &lt; 6) {<br>            System.out.println(&quot;Manager &quot; + this.name <br>                               + &quot; approved!&quot;);<br>            req.setApproved();<br>        } else {<br>            System.out.println(&quot;Manager &quot; + this.name <br>                               + &quot; signed.&quot;);<br>        }<br>    }<br>}</pre><pre>public class GeneralManager extends Staff {<br>    public GeneralManager(String name) {<br>        super(name);<br>    }</pre><pre>    @Override<br>    public void handle(Request req) {<br>        System.out.println(&quot;General Manager &quot; + this.name <br>                           + &quot; approved!&quot;);<br>        req.setApproved();<br>    }<br>}</pre><p>Client</p><pre>public class Client {<br>    public static void main(String[] args) {<br>        // build the handler chain<br>        Staff teamLeader = new TeamLeader(&quot;Bob&quot;);<br>        Staff manager = new Manager(&quot;Cook&quot;);<br>        Staff generalManager = new GeneralManager(&quot;Dora&quot;);<br>        teamLeader.setNextStaff(manager);<br>        manager.setNextStaff(generalManager);<br>        <br>        // send a 1 day sick leave application to TL<br>        Request req1 = new Request(&quot;Alice&quot;, 1, &quot;Sick&quot;);<br>        teamLeader.receiveRequest(req1);</pre><pre>        // send a 5 days off application to TL<br>        Request req2 = new Request(&quot;Ellie&quot;, 5, &quot;Travel&quot;);<br>        teamLeader.receiveRequest(req2);</pre><pre>        Request req3 = new Request(&quot;Ellie&quot;, 10, &quot;Marry&quot;);<br>        teamLeader.receiveRequest(req3);<br>    }<br>}</pre><pre>public class Request {<br>    String name;<br>    int days;<br>    String reason;<br>    boolean approved;<br>    <br>    public Request(String name, int days, String reason) {<br>        System.out.println(name + &quot; has sent a day off request: &quot; <br>                           + days + &quot; days.&quot;);<br>        this.name = name;<br>        this.days = days;<br>        this.reason = reason;<br>        this.approved = false;<br>    }<br>    public void setApproved() {<br>        this.approved = true;<br>        System.out.println(&quot;\n&quot;);<br>    }<br>}</pre><p>Output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*vzJ2FuynNflW3VQ_FAYXxQ.png" /></figure><h4>Pros and cons</h4><p>Reduced Coupling<br>- Sender do not need to know who is the final handler.<br>- Client and the receiver do not need to know the whole structure of the chain, only know who is the next.</p><p>Flexibility<br>- The structure of the chain and the responsibility of the request can be distributed dynamically.</p><p>Receipt not guaranteed (Con)<br>- There are no guarantee that the request be handled by one of the handler.</p><h4>Common Usages</h4><ol><li>Authentication Filter</li><li>Logging Filter</li><li>Data Compression Filte</li><li>Encryption Filter</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ea924e816e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>