<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Roy 的解題紀錄</title>
  <icon>http://oj.roy4801.tw/icon.png</icon>
  
  <link href="http://oj.roy4801.tw/atom.xml" rel="self"/>
  
  <link href="http://oj.roy4801.tw/"/>
  <updated>2024-07-04T14:41:54.805Z</updated>
  <id>http://oj.roy4801.tw/</id>
  
  <author>
    <name>Roy</name>
    
  </author>
  
  <generator uri="https://hexo.io/">Hexo</generator>
  
  <entry>
    <title>Leetcode 2181 - Merge Nodes in Between Zeros</title>
    <link href="http://oj.roy4801.tw/2024/07/04/leetcode/2181/"/>
    <id>http://oj.roy4801.tw/2024/07/04/leetcode/2181/</id>
    <published>2024-07-04T22:22:06.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/merge-nodes-in-between-zeros&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2022/02/02/ex1-1.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個 linked-list 每個節點有一個整數，裡面有節點數字 &lt;code&gt;0&lt;/code&gt; 隔開(如上圖)，對於每個 &lt;code&gt;0&lt;/code&gt; 圍起來的區間，可以相加合併起來成為一個節點，問你能不能合併完所有區間，然後回傳&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1509 - Minimum Difference Between Largest and Smallest Value in Three Moves</title>
    <link href="http://oj.roy4801.tw/2024/07/03/leetcode/1509/"/>
    <id>http://oj.roy4801.tw/2024/07/03/leetcode/1509/</id>
    <published>2024-07-03T23:02:25.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-difference-between-largest-and-smallest-value-in-three-moves&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 你可以從中挑一個數字將其改寫成另一個數字，要操作三次，問你操作完時，陣列中最大的數字和最小的數字之「差」最小是多少?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$-10^9 &#92;le val &#92;le 10^9$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
    <category term="sort" scheme="http://oj.roy4801.tw/tags/sort/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 409 - Longest Palindrome</title>
    <link href="http://oj.roy4801.tw/2024/06/04/leetcode/409/"/>
    <id>http://oj.roy4801.tw/2024/06/04/leetcode/409/</id>
    <published>2024-06-04T21:43:20.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/longest-palindrome&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 包含小寫和大寫的字元，回傳可以組成最長的迴文字串長度，大小寫視為不同字元&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 2000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1863 - Sum of All Subset XOR Totals</title>
    <link href="http://oj.roy4801.tw/2024/05/20/leetcode/1863/"/>
    <id>http://oj.roy4801.tw/2024/05/20/leetcode/1863/</id>
    <published>2024-05-20T20:35:46.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/sum-of-all-subset-xor-totals&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt;，將其元素經過 XOR 運算會得到一個值，稱作 XOR total，問題 &lt;code&gt;nums&lt;/code&gt; 的所有子集合陣列的 XOR total 加總起來是多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 12$&lt;/li&gt;
&lt;li&gt;$1 &#92;le val &#92;le 20$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="bitwise 枚舉" scheme="http://oj.roy4801.tw/tags/bitwise-%E6%9E%9A%E8%88%89/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 861 - Score After Flipping Matrix</title>
    <link href="http://oj.roy4801.tw/2024/05/13/leetcode/861/"/>
    <id>http://oj.roy4801.tw/2024/05/13/leetcode/861/</id>
    <published>2024-05-13T23:35:02.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/score-after-flipping-matrix&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 $m &#92;times n$ 的二維陣列 &lt;code&gt;grid&lt;/code&gt; 裡面只包含 &lt;code&gt;0&lt;/code&gt; 和 &lt;code&gt;1&lt;/code&gt;，你可以對每行、列進行 flip 操作(&lt;code&gt;0&lt;/code&gt; 變 &lt;code&gt;1&lt;/code&gt;，&lt;code&gt;1&lt;/code&gt; 變 &lt;code&gt;0&lt;/code&gt;)，每列可以組成一個 binary 數字，最後加總起來就是分數，你可以 flip 無限次(或不 flip)，問你最大的分數是多少。&lt;/p&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/07/23/lc-toogle1.jpg&quot; width=&quot;50%&quot;&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 404 - Sum of Left Leaves</title>
    <link href="http://oj.roy4801.tw/2024/04/14/leetcode/404/"/>
    <id>http://oj.roy4801.tw/2024/04/14/leetcode/404/</id>
    <published>2024-04-14T20:29:40.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/sum-of-left-leaves&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 binary tree 問你所有左 leaf 節點的總和是多少?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;li&gt;$-1000 &#92;le val &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2073 - Time Needed to Buy Tickets</title>
    <link href="http://oj.roy4801.tw/2024/04/09/leetcode/2073/"/>
    <id>http://oj.roy4801.tw/2024/04/09/leetcode/2073/</id>
    <published>2024-04-09T20:54:44.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/time-needed-to-buy-tickets&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 $n$ 個人排隊買票，每個人想買 &lt;code&gt;tickets[i]&lt;/code&gt; 張票，每次買票要花一秒鐘，問你第 $k$ 個人買完票的時候，總共花了幾秒?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;n = tickets.size()&lt;/code&gt; $1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;&lt;code&gt;m = tickets[i]&lt;/code&gt; $1 &#92;le m &#92;le 100$&lt;/li&gt;
&lt;li&gt;$0 &#92;le k &amp;lt; n$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 678 - Valid Parenthesis String</title>
    <link href="http://oj.roy4801.tw/2024/04/07/leetcode/678/"/>
    <id>http://oj.roy4801.tw/2024/04/07/leetcode/678/</id>
    <published>2024-04-07T21:28:30.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/valid-parenthesis-string&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 其中只包含三種字元: &lt;code&gt;(&lt;/code&gt;, &lt;code&gt;)&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;，所有的括號必須左右匹配，右括號必須在左括號後面，星號可以變成左、右括號、或空字串，回傳字串 &lt;code&gt;s&lt;/code&gt; 是否合法。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 287 - Find the Duplicate Number</title>
    <link href="http://oj.roy4801.tw/2024/03/25/leetcode/287/"/>
    <id>http://oj.roy4801.tw/2024/03/25/leetcode/287/</id>
    <published>2024-03-25T00:12:29.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 包含 $n+1$ 個整數，值域 $[1, n]$，陣列裡面只包含一個重複的數字，找出這個重複的數字並回傳。&lt;br&gt;
限制: 不能修改原本的陣列，且空間複雜度必須在 $O(1)$&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Follow up:
&lt;ul&gt;
&lt;li&gt;證明陣列裡面只包含一個重複的數字的正確性?&lt;/li&gt;
&lt;li&gt;解在 $O(n)$ 時間複雜度內&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="cycle detection" scheme="http://oj.roy4801.tw/tags/cycle-detection/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
    <category term="sort" scheme="http://oj.roy4801.tw/tags/sort/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 206 - Reverse Linked List</title>
    <link href="http://oj.roy4801.tw/2024/03/21/leetcode/206/"/>
    <id>http://oj.roy4801.tw/2024/03/21/leetcode/206/</id>
    <published>2024-03-21T19:31:19.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;hhttps://leetcode.com/problems/reverse-linked-list/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/02/19/rev1ex1.jpg&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個單向 linked-list &lt;code&gt;head&lt;/code&gt; 叫你把它反轉&lt;/p&gt;
&lt;p&gt;Follow-up: recursively 和 iteratively 都要實作一次&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1669 - Merge In Between Linked Lists</title>
    <link href="http://oj.roy4801.tw/2024/03/20/leetcode/1669/"/>
    <id>http://oj.roy4801.tw/2024/03/20/leetcode/1669/</id>
    <published>2024-03-20T20:32:36.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/merge-in-between-linked-lists/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/11/05/fig1.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你兩個 linked-list &lt;code&gt;A&lt;/code&gt; 和 &lt;code&gt;B&lt;/code&gt; 長度分別是 &lt;code&gt;n&lt;/code&gt; 和 &lt;code&gt;m&lt;/code&gt;，並給你兩個正整數 &lt;code&gt;a&lt;/code&gt; 和 &lt;code&gt;b&lt;/code&gt; 代表要從 &lt;code&gt;A&lt;/code&gt; 中移除第 &lt;code&gt;a&lt;/code&gt; 個到第 &lt;code&gt;b&lt;/code&gt; 個 node，之後用 &lt;code&gt;B&lt;/code&gt; 替代，要你回傳替代後的結果。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 238 - Product of Array Except Self</title>
    <link href="http://oj.roy4801.tw/2024/03/15/leetcode/238/"/>
    <id>http://oj.roy4801.tw/2024/03/15/leetcode/238/</id>
    <published>2024-03-15T19:38:06.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt;，要你回傳答案陣列 &lt;code&gt;answer[i] = nums[0] *  ... * nums[i-1] * nums[i+1] * ... * nums[n-1]&lt;/code&gt; (也就是除了 &lt;code&gt;nums[i]&lt;/code&gt; 之外的相乘）&lt;br&gt;
時間複雜度必須在 $O(n)$。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$-30 &#92;le val &#92;le 30$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="prefix sum" scheme="http://oj.roy4801.tw/tags/prefix-sum/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2485 - Find the Pivot Integer</title>
    <link href="http://oj.roy4801.tw/2024/03/13/leetcode/2485/"/>
    <id>http://oj.roy4801.tw/2024/03/13/leetcode/2485/</id>
    <published>2024-03-13T20:11:58.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你正整數 $n$ 要你找到 pivot $i$ 使得 $1+2+&#92;cdots +i = i + (i+1) + (i+2) + &#92;cdots + n$，如果找不到則回傳 &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="prefix sum" scheme="http://oj.roy4801.tw/tags/prefix-sum/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 791 - Custom Sort String</title>
    <link href="http://oj.roy4801.tw/2024/03/11/leetcode/791/"/>
    <id>http://oj.roy4801.tw/2024/03/11/leetcode/791/</id>
    <published>2024-03-11T22:47:54.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/custom-sort-string/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;order&lt;/code&gt; 和 &lt;code&gt;s&lt;/code&gt;，要你把 &lt;code&gt;s&lt;/code&gt; 按照 &lt;code&gt;order&lt;/code&gt; 的字母順序排序，沒出現在裡面的字母位置隨意，回傳排序後的字串。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le &#92;text{order} &#92;le 26$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{s} &#92;le 200$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="sort" scheme="http://oj.roy4801.tw/tags/sort/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 3067 - Count Pairs of Connectable Servers in a Weighted Tree Network</title>
    <link href="http://oj.roy4801.tw/2024/03/03/leetcode/3067/"/>
    <id>http://oj.roy4801.tw/2024/03/03/leetcode/3067/</id>
    <published>2024-03-03T01:47:00.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-pairs-of-connectable-servers-in-a-weighted-tree-network&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2024/01/21/example11.png&quot; width=&quot;400&quot;&gt;
&lt;p&gt;給你一個有 $n$ 個點的無向圖，另外給你一個整數 &lt;code&gt;ss&lt;/code&gt;。&lt;/p&gt;
&lt;p&gt;定義點 &lt;code&gt;a&lt;/code&gt; 與點 &lt;code&gt;b&lt;/code&gt; 之間是否是透過點 &lt;code&gt;c&lt;/code&gt; 連接的，必須符合以下條件:&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2864 - Maximum Odd Binary Number</title>
    <link href="http://oj.roy4801.tw/2024/03/01/leetcode/2864/"/>
    <id>http://oj.roy4801.tw/2024/03/01/leetcode/2864/</id>
    <published>2024-03-01T19:42:14.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-odd-binary-number&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你只有 &lt;code&gt;0&lt;/code&gt; 和 &lt;code&gt;1&lt;/code&gt; （至少包含一個） 的字串 &lt;code&gt;s&lt;/code&gt; ，你可以將 bit 自由交換位置，問你最大的奇數是多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 100 - Same Tree</title>
    <link href="http://oj.roy4801.tw/2024/02/26/leetcode/100/"/>
    <id>http://oj.roy4801.tw/2024/02/26/leetcode/100/</id>
    <published>2024-02-26T20:05:47.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/same-tree&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你兩個 binary tree &lt;code&gt;p&lt;/code&gt; 和 &lt;code&gt;q&lt;/code&gt; 要你寫一個程式判斷兩棵樹是否一樣。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 997 - Find the Town Judge</title>
    <link href="http://oj.roy4801.tw/2024/02/22/leetcode/997/"/>
    <id>http://oj.roy4801.tw/2024/02/22/leetcode/997/</id>
    <published>2024-02-22T23:43:10.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-town-judge&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 $n$ 個人標號 $[1, n]$ 其中有一個人是城鎮法官滿足兩個條件：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;城鎮法官不相信任何人&lt;/li&gt;
&lt;li&gt;其他人都相信城鎮法官&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;trust[i] = [ai, bi]&lt;/code&gt; 代表 $a_i$ 相信 $b_i$，回傳法官的編號，沒有的話回傳 &lt;code&gt;-1&lt;/code&gt;。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 268 - Missing Number</title>
    <link href="http://oj.roy4801.tw/2024/02/20/leetcode/268/"/>
    <id>http://oj.roy4801.tw/2024/02/20/leetcode/268/</id>
    <published>2024-02-20T19:40:00.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/missing-number&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個大小 $n$ 的不重覆整數陣列 &lt;code&gt;nums&lt;/code&gt;，數字範圍 $[0, n]$，要你回傳唯一不在範圍內的數字。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 231 - Power of Two</title>
    <link href="http://oj.roy4801.tw/2024/02/20/leetcode/231/"/>
    <id>http://oj.roy4801.tw/2024/02/20/leetcode/231/</id>
    <published>2024-02-20T00:27:18.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/power-of-two&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數 &lt;code&gt;n&lt;/code&gt; 問你它是不是 $2^x$？&lt;/p&gt;
&lt;p&gt;Follow up: 不用 loop/recursion?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 3040 - Maximum Number of Operations With the Same Score II</title>
    <link href="http://oj.roy4801.tw/2024/02/18/leetcode/3040/"/>
    <id>http://oj.roy4801.tw/2024/02/18/leetcode/3040/</id>
    <published>2024-02-18T21:21:49.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-ii&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 你可以做三種操作:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;刪除開頭兩個數字&lt;/li&gt;
&lt;li&gt;刪除結尾兩個數字&lt;/li&gt;
&lt;li&gt;刪除頭尾各一個數字&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;問你最多可以做幾次操作，且每次操作所刪除的數字加起來都要相同&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 3039 - Apply Operations to Make String Empty</title>
    <link href="http://oj.roy4801.tw/2024/02/18/leetcode/3039/"/>
    <id>http://oj.roy4801.tw/2024/02/18/leetcode/3039/</id>
    <published>2024-02-18T20:07:41.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/apply-operations-to-make-string-empty&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt;，每次都從中刪除所有第一次出現的字元，問你刪除到最後一步(再刪除一次就變成空字串)時，所刪除的子字串是什麼?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le s &#92;le 5 &#92;cdot 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 3038 - Maximum Number of Operations With the Same Score I</title>
    <link href="http://oj.roy4801.tw/2024/02/18/leetcode/3038/"/>
    <id>http://oj.roy4801.tw/2024/02/18/leetcode/3038/</id>
    <published>2024-02-18T04:49:40.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-number-of-operations-with-the-same-score-i&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 你每次可以從中刪除頭兩個數字，問你對於這個整數陣列來說，&lt;strong&gt;最多&lt;/strong&gt;可以刪除幾次且每次刪除的數字加總起來要一樣，回傳最多可以刪除的次數。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;$1 &#92;le val &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1481 - Least Number of Unique Integers after K Removals</title>
    <link href="http://oj.roy4801.tw/2024/02/16/leetcode/1481/"/>
    <id>http://oj.roy4801.tw/2024/02/16/leetcode/1481/</id>
    <published>2024-02-16T20:36:34.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;arr&lt;/code&gt; 和一個整數 &lt;code&gt;k&lt;/code&gt; ，問你在移除 &lt;code&gt;k&lt;/code&gt; 個元素後剩下&lt;strong&gt;最少&lt;/strong&gt;幾種不同的數字？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le val &#92;le 10^9$&lt;/li&gt;
&lt;li&gt;$0 &#92;le k &#92;le n$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2108 - Find First Palindromic String in the Array</title>
    <link href="http://oj.roy4801.tw/2024/02/13/leetcode/2108/"/>
    <id>http://oj.roy4801.tw/2024/02/13/leetcode/2108/</id>
    <published>2024-02-13T20:13:42.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-first-palindromic-string-in-the-array&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串陣列 &lt;code&gt;words&lt;/code&gt; 回傳第一個是回文的字串，如果沒有的話回傳空字串。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n, s &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 279 - Perfect Squares</title>
    <link href="http://oj.roy4801.tw/2024/02/08/leetcode/279/"/>
    <id>http://oj.roy4801.tw/2024/02/08/leetcode/279/</id>
    <published>2024-02-08T19:14:55.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/perfect-squares&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數 &lt;code&gt;n&lt;/code&gt;，回傳最少需要幾個完全平方數加起來等於它?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 387 - First Unique Character in a String</title>
    <link href="http://oj.roy4801.tw/2024/02/05/leetcode/387/"/>
    <id>http://oj.roy4801.tw/2024/02/05/leetcode/387/</id>
    <published>2024-02-05T19:45:40.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/first-unique-character-in-a-string&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給字串 &lt;code&gt;s&lt;/code&gt; 回傳第一個非重複字元的 index，如果不存在則回傳 &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2966 - Divide Array Into Arrays With Max Difference</title>
    <link href="http://oj.roy4801.tw/2024/02/01/leetcode/2966/"/>
    <id>http://oj.roy4801.tw/2024/02/01/leetcode/2966/</id>
    <published>2024-02-01T21:57:08.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/divide-array-into-arrays-with-max-difference&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 大小 &lt;code&gt;n&lt;/code&gt; 還有一個正整數 &lt;code&gt;k&lt;/code&gt;，問你 &lt;code&gt;nums&lt;/code&gt; 可不可以變成一推大小 &lt;code&gt;3&lt;/code&gt; 的子陣列，每個子陣列中最大與最小的差不能超過 &lt;code&gt;k&lt;/code&gt;，如果可以的話，回傳轉換後的陣列；不能的話，回傳空陣列。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n, k &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{nums}[i] &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 380 - Insert Delete GetRandom O(1)</title>
    <link href="http://oj.roy4801.tw/2024/01/16/leetcode/380/"/>
    <id>http://oj.roy4801.tw/2024/01/16/leetcode/380/</id>
    <published>2024-01-16T21:46:29.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/insert-delete-getrandom-o1&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;要你實作一個 class &lt;code&gt;RandomizedSet()&lt;/code&gt; 有三個操作: 插入數字、移除數字、隨機取出數字，三種操作都必須在平均 $O(1)$ 時間複雜度下。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$-2^{31} &#92;le val &#92;le 2^{31} - 1$&lt;/li&gt;
&lt;li&gt;最多 $2&#92;cdot 10^5$ 次呼叫&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="Design" scheme="http://oj.roy4801.tw/tags/Design/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2225 - Find Players With Zero or One Losses</title>
    <link href="http://oj.roy4801.tw/2024/01/15/leetcode/2225/"/>
    <id>http://oj.roy4801.tw/2024/01/15/leetcode/2225/</id>
    <published>2024-01-15T19:47:40.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-players-with-zero-or-one-losses&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;match[i] = (winner_i, loser_i)&lt;/code&gt; 代表&lt;code&gt;winner_i&lt;/code&gt; 在第 &lt;code&gt;i&lt;/code&gt; 場比賽贏了 &lt;code&gt;loser_i&lt;/code&gt;，要你回傳沒有輸過的人、和只輸一場的人有哪些（回傳要遞增排序）。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{winner}_i, &#92;text{loser}_i &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1657 - Determine if Two Strings Are Close</title>
    <link href="http://oj.roy4801.tw/2024/01/14/leetcode/1657/"/>
    <id>http://oj.roy4801.tw/2024/01/14/leetcode/1657/</id>
    <published>2024-01-14T21:26:02.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/determine-if-two-strings-are-close&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;word1&lt;/code&gt;, &lt;code&gt;word2&lt;/code&gt; 你可以對它做以下兩個操作:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;交換任意兩個字元 e.g. &lt;code&gt;abcde -&amp;gt; aecdb&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;選擇一組字元(不限長度、可以不用連續)，可以互相交換字元 e.g. &lt;code&gt;aacabb -&amp;gt; bbcbaa&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;你可以做無限次操作，把 &lt;code&gt;word1&lt;/code&gt; 和 &lt;code&gt;word2&lt;/code&gt; 做完操作後會一樣回傳 &lt;code&gt;true&lt;/code&gt; 反之回傳 &lt;code&gt;false&lt;/code&gt;。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2085 - Count Common Words With One Occurrence</title>
    <link href="http://oj.roy4801.tw/2024/01/12/leetcode/2085/"/>
    <id>http://oj.roy4801.tw/2024/01/12/leetcode/2085/</id>
    <published>2024-01-12T21:47:43.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-common-words-with-one-occurrence&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串鎮列 &lt;code&gt;words1&lt;/code&gt; 和 &lt;code&gt;words2&lt;/code&gt; 問你兩個陣列都只出現一次的字串數量有多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2385 - Amount of Time for Binary Tree to Be Infected</title>
    <link href="http://oj.roy4801.tw/2024/01/10/leetcode/2385/"/>
    <id>http://oj.roy4801.tw/2024/01/10/leetcode/2385/</id>
    <published>2024-01-10T23:56:53.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/amount-of-time-for-binary-tree-to-be-infected&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 binary tree 的 &lt;code&gt;root&lt;/code&gt; 上面的值都不重複，另外給你一個數字 &lt;code&gt;start&lt;/code&gt;，問你從該數字的 node 為 root，最大深度為多少?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le val &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="bfs" scheme="http://oj.roy4801.tw/tags/bfs/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 872 - Leaf-Similar Trees</title>
    <link href="http://oj.roy4801.tw/2024/01/09/leetcode/872/"/>
    <id>http://oj.roy4801.tw/2024/01/09/leetcode/872/</id>
    <published>2024-01-09T13:24:22.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/leaf-similar-trees&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/09/03/leaf-similar-1.jpg&quot; width=&quot;30%&quot;&gt;
&lt;p&gt;Leaf value sequence 為二元樹的所有葉節點(Leaf)，從左至右輸出的序列。&lt;br&gt;
給你兩個二元樹，問你兩個 leaf value sequence 是否一樣？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 300 - Longest Increasing Subsequence</title>
    <link href="http://oj.roy4801.tw/2024/01/05/leetcode/300/"/>
    <id>http://oj.roy4801.tw/2024/01/05/leetcode/300/</id>
    <published>2024-01-05T20:30:54.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/longest-increasing-subsequence&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列，回傳其最長嚴格遞增子序列(LIS)。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 2500$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
    <category term="LIS" scheme="http://oj.roy4801.tw/tags/LIS/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2870 - Minimum Number of Operations to Make Array Empty</title>
    <link href="http://oj.roy4801.tw/2024/01/04/leetcode/2870/"/>
    <id>http://oj.roy4801.tw/2024/01/04/leetcode/2870/</id>
    <published>2024-01-04T20:15:20.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-number-of-operations-to-make-array-empty&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個正整數陣列 &lt;code&gt;nums&lt;/code&gt;，你對陣列做以下操作：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;從裡面刪掉 2 個一樣的數字&lt;/li&gt;
&lt;li&gt;從裡面刪掉 3 個一樣的數字&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;回傳最少要多少次操作，能使 &lt;code&gt;nums&lt;/code&gt; 變空？如果無法則回傳 &lt;code&gt;-1&lt;/code&gt;。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2125 - Number of Laser Beams in a Bank</title>
    <link href="http://oj.roy4801.tw/2024/01/03/leetcode/2125/"/>
    <id>http://oj.roy4801.tw/2024/01/03/leetcode/2125/</id>
    <published>2024-01-03T20:37:10.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/number-of-laser-beams-in-a-bank/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 $m &#92;times n$ 的陣列 &lt;code&gt;bank&lt;/code&gt; 裡頭只包含 &lt;code&gt;0&lt;/code&gt;（空的）, &lt;code&gt;1&lt;/code&gt;（機器），對於相鄰兩列的機器，對於第 $i$ 列的每台機器會和第 $j$ 列的每台機器用雷射相連，中間不能間隔其他機器，問你總共有多少條雷射？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le m, n &#92;le 500$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
    <category term="matrix" scheme="http://oj.roy4801.tw/tags/matrix/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2610 - Convert an Array Into a 2D Array With Conditions</title>
    <link href="http://oj.roy4801.tw/2024/01/02/leetcode/2610/"/>
    <id>http://oj.roy4801.tw/2024/01/02/leetcode/2610/</id>
    <published>2024-01-02T19:56:04.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/convert-an-array-into-a-2d-array-with-conditions/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 你要把它根據以下規則排成一個二維陣列回傳。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;陣列的每列元素皆不重複&lt;/li&gt;
&lt;li&gt;列的數量應越少越好&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;如果有多組解則回傳任一一種即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1578 - Minimum Time to Make Rope Colorful</title>
    <link href="http://oj.roy4801.tw/2023/12/27/leetcode/1578/"/>
    <id>http://oj.roy4801.tw/2023/12/27/leetcode/1578/</id>
    <published>2023-12-27T23:07:53.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-time-to-make-rope-colorful/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/12/13/ballon1.jpg&quot; width=&quot;35%/&quot;&gt;
&lt;p&gt;有 $n$ 個氣球，每個氣球是 &lt;code&gt;color[i]&lt;/code&gt; 顏色，顏色不能連續出現，如果有相鄰的顏色的話，可以花 &lt;code&gt;neededTime[i]&lt;/code&gt; 戳破第 $i$ 個氣球。&lt;br&gt;
問你總共最小要花多少時間讓所有氣球的顏色不連續?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1155 - Number of Dice Rolls With Target Sum</title>
    <link href="http://oj.roy4801.tw/2023/12/27/leetcode/1155/"/>
    <id>http://oj.roy4801.tw/2023/12/27/leetcode/1155/</id>
    <published>2023-12-27T00:03:13.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;你有 $n$ 個 $k$ 面骰子，點數是 $1$ 到 $k$ ，給你一個目標數字 $t$，問你連續投骰子，最後點數加總起來等於 $t$ 的方法數有多少?&lt;br&gt;
答案可能很大，因此回傳前要模除 $10^9+7$ 。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n, k &#92;le 30$&lt;/li&gt;
&lt;li&gt;$1 &#92;le t &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1422 - Maximum Score After Splitting a String</title>
    <link href="http://oj.roy4801.tw/2023/12/22/leetcode/1422/"/>
    <id>http://oj.roy4801.tw/2023/12/22/leetcode/1422/</id>
    <published>2023-12-22T22:09:23.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-score-after-splitting-a-string/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 你可以把它從任意 index 切成兩半，問你左邊字串 &lt;code&gt;0&lt;/code&gt; 的數量與右邊字串 &lt;code&gt;1&lt;/code&gt; 的數量相加最大多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
    <category term="prefix sum" scheme="http://oj.roy4801.tw/tags/prefix-sum/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1637 - Widest Vertical Area Between Two Points Containing No Points</title>
    <link href="http://oj.roy4801.tw/2023/12/21/leetcode/1637/"/>
    <id>http://oj.roy4801.tw/2023/12/21/leetcode/1637/</id>
    <published>2023-12-21T09:36:38.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 $n$ 個點 &lt;code&gt;points[i] = [x_i, y_i]&lt;/code&gt; 問你兩個點可以框出，且中間沒有任何其他點的最大矩形寬度多少？&lt;br&gt;
（假設矩形上下無限延伸）&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2706 - Buy Two Chocolates</title>
    <link href="http://oj.roy4801.tw/2023/12/20/leetcode/2706/"/>
    <id>http://oj.roy4801.tw/2023/12/20/leetcode/2706/</id>
    <published>2023-12-20T09:30:08.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/buy-two-chocolates/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;money&lt;/code&gt; 塊錢，陣列 &lt;code&gt;price[i]&lt;/code&gt; 代表巧克力的價錢，你必須買兩個，問你每次買最少價錢的巧克力後，會剩多少錢？如果錢不夠買完兩個，則放棄回傳 &lt;code&gt;money&lt;/code&gt; 即可&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le &#92;text{money} &#92;le 100$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{prices}[i] &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 661 - Image Smoother</title>
    <link href="http://oj.roy4801.tw/2023/12/19/leetcode/661/"/>
    <id>http://oj.roy4801.tw/2023/12/19/leetcode/661/</id>
    <published>2023-12-19T20:14:34.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/image-smoother/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 $n &#92;times m$ 的陣列代表圖片 &lt;code&gt;img&lt;/code&gt;，要你回傳經過 smoother filter 的結果。&lt;/p&gt;
&lt;p&gt;smoother filter: 對於一個 pixel (&lt;code&gt;img[i][j]&lt;/code&gt;) 經過 filter 後會是周圍 $3&#92;times 3$ 的總和除以數量的下高斯。`&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
    <category term="matrix" scheme="http://oj.roy4801.tw/tags/matrix/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1913 - Maximum Product Difference Between Two Pairs</title>
    <link href="http://oj.roy4801.tw/2023/12/18/leetcode/1913/"/>
    <id>http://oj.roy4801.tw/2023/12/18/leetcode/1913/</id>
    <published>2023-12-18T20:00:28.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-product-difference-between-two-pairs/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 從裡頭挑 4 個數字: &lt;code&gt;w&lt;/code&gt;, &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;, &lt;code&gt;z&lt;/code&gt; 使得 &lt;code&gt;(w * x) - (y * z)&lt;/code&gt; 最大，回傳最大值。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$4 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1436 - Destination City</title>
    <link href="http://oj.roy4801.tw/2023/12/15/leetcode/1436/"/>
    <id>http://oj.roy4801.tw/2023/12/15/leetcode/1436/</id>
    <published>2023-12-15T18:10:19.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/destination-city/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串陣列 &lt;code&gt;path&lt;/code&gt; 其中 &lt;code&gt;path[i] = [city_a, city_b]&lt;/code&gt; 代表從 &lt;code&gt;A&lt;/code&gt; 城市到 &lt;code&gt;B&lt;/code&gt; 城市存在路徑，問你回傳最後到達的城市名稱（即沒有通往其他城市的路徑之城市）&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;保證測資一定構成一條直線，只有一個終點城市，沒有環&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2482 - Difference Between Ones and Zeros in Row and Column</title>
    <link href="http://oj.roy4801.tw/2023/12/14/leetcode/2482/"/>
    <id>http://oj.roy4801.tw/2023/12/14/leetcode/2482/</id>
    <published>2023-12-14T19:36:55.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 $m &#92;times n$ 只有 $0$ 和 $1$ 的 matrix &lt;code&gt;grid&lt;/code&gt;，要你計算 &lt;code&gt;diff&lt;/code&gt; 矩陣並回傳。&lt;br&gt;
其中 &lt;code&gt;diff[i][j]&lt;/code&gt; 代表第 &lt;code&gt;i&lt;/code&gt; row 與第 &lt;code&gt;j&lt;/code&gt; column 的 $1$ 的數量相加 減去 $0$ 的數量相加&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le m, n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le m &#92;times n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
    <category term="Leetcod" scheme="http://oj.roy4801.tw/tags/Leetcod/"/>
    
    <category term="matrixe" scheme="http://oj.roy4801.tw/tags/matrixe/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1582 - Special Positions in a Binary Matrix</title>
    <link href="http://oj.roy4801.tw/2023/12/13/leetcode/1582/"/>
    <id>http://oj.roy4801.tw/2023/12/13/leetcode/1582/</id>
    <published>2023-12-13T19:48:41.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/special-positions-in-a-binary-matrix/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 $mxn$ 的矩陣(&lt;code&gt;mat&lt;/code&gt;)，對於 &lt;code&gt;mat[i][j]&lt;/code&gt; 來說，第 &lt;code&gt;i&lt;/code&gt; 列第 &lt;code&gt;j&lt;/code&gt; 排的數字如果只有它是 &lt;code&gt;1&lt;/code&gt; 其餘都是 &lt;code&gt;0&lt;/code&gt; 的話則稱作特殊位置。問你屬於特殊位置的數字有幾個？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le m, n &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1464 - Maximum Product of Two Elements in an Array</title>
    <link href="http://oj.roy4801.tw/2023/12/12/leetcode/1464/"/>
    <id>http://oj.roy4801.tw/2023/12/12/leetcode/1464/</id>
    <published>2023-12-12T19:50:47.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-product-of-two-elements-in-an-array/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;nums&lt;/code&gt;，你要挑兩個 index &lt;code&gt;i&lt;/code&gt; 和 &lt;code&gt;j&lt;/code&gt; ，回傳 &lt;code&gt;(nums[i]-1) * (nums[j]-1)&lt;/code&gt; 的最大值。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;li&gt;$1 &#92;le val &#92;le 10^3$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 191 - Number of 1 Bits</title>
    <link href="http://oj.roy4801.tw/2023/11/29/leetcode/191/"/>
    <id>http://oj.roy4801.tw/2023/11/29/leetcode/191/</id>
    <published>2023-11-29T21:33:15.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/number-of-1-bits/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 32-bit 的無號整數，要你回傳有幾個 1 (又稱作 &lt;code&gt;Hamming weight&lt;/code&gt;)。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Naive: 每個 bit 都檢查是不是 1 然後記數。&lt;br&gt;
Improve: 每次找最右邊的 1-bit，可以把數字 $n$ 與 $n-1$ 做 AND 運算，因為減一的話最右邊的 1 就會被消滅，經過 and 運算就會消失，直到變成 0。&lt;br&gt;
或是可以用編譯器內建的 &lt;a href=&quot;https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fpopcount&quot;&gt;&lt;code&gt;__builtin_popcount()&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 935 - Knight Dialer</title>
    <link href="http://oj.roy4801.tw/2023/11/28/leetcode/935/"/>
    <id>http://oj.roy4801.tw/2023/11/28/leetcode/935/</id>
    <published>2023-11-28T00:13:13.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/knight-dialer/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/08/18/chess.jpg&quot; width=&quot;15%&quot;&gt;
&lt;p&gt;你能操縱一個西洋棋的騎士(Knight)旗子，它只能走 L 字形。&lt;/p&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/08/18/phone.jpg&quot; width=&quot;15%&quot;&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1685 - Sum of Absolute Differences in a Sorted Array</title>
    <link href="http://oj.roy4801.tw/2023/11/25/leetcode/1685/"/>
    <id>http://oj.roy4801.tw/2023/11/25/leetcode/1685/</id>
    <published>2023-11-25T20:20:28.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/sum-of-absolute-differences-in-a-sorted-array/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個遞減排序的整數陣列 &lt;code&gt;nums&lt;/code&gt; ，要你回傳另一個整數陣列 &lt;code&gt;result[i]&lt;/code&gt; 代表 &lt;code&gt;nums[i]&lt;/code&gt; 與 &lt;code&gt;nums&lt;/code&gt; 裡的所有數字的差距的絕對值總和。&lt;br&gt;
&lt;code&gt;result[i] = sum(|nums[i]-nums[j]|)&lt;/code&gt; where &lt;code&gt;0 &amp;lt;= j &amp;lt; nums.length &amp;amp;&amp;amp; j != i&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{nums}[i] &#92;le &#92;text{nums}[i+1] &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="prefix sum" scheme="http://oj.roy4801.tw/tags/prefix-sum/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1561 - Maximum Number of Coins You Can Get</title>
    <link href="http://oj.roy4801.tw/2023/11/24/leetcode/1561/"/>
    <id>http://oj.roy4801.tw/2023/11/24/leetcode/1561/</id>
    <published>2023-11-24T22:41:09.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-number-of-coins-you-can-get/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;你有 $3n$ 個堆錢，有三個人參加遊戲，每次你先挑三堆錢，接著 B 拿最大的，接著換你拿最大的，剩下的 C 拿。&lt;br&gt;
一直這樣持續直到所有錢都分完，問你最大能拿多少錢?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;幾堆錢: $3 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;每堆錢數量: $1 &#92;le val &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1630 - Arithmetic Subarrays</title>
    <link href="http://oj.roy4801.tw/2023/11/23/leetcode/1630/"/>
    <id>http://oj.roy4801.tw/2023/11/23/leetcode/1630/</id>
    <published>2023-11-23T22:21:56.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/arithmetic-subarrays/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt;，如果可以重排成: 其中的整個陣列的&lt;strong&gt;相鄰數字的差&lt;/strong&gt;(&lt;code&gt;s[i+1] - s[i] == s[1] - s[0]&lt;/code&gt;)相同的話代表 true 反之代表 false。&lt;br&gt;
還有兩個整數陣列 &lt;code&gt;L&lt;/code&gt; 和 &lt;code&gt;R&lt;/code&gt;，其中 &lt;code&gt;[L[i], R[i]]&lt;/code&gt; 代表查詢 &lt;code&gt;nums&lt;/code&gt; 中 index 範圍的數字是 true 還 false，會把答案存在陣列並回傳。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;nums&lt;/code&gt; 大小: $2 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;li&gt;&lt;code&gt;L&lt;/code&gt;, &lt;code&gt;R&lt;/code&gt; 大小: $1 &#92;le m &#92;le 500$&lt;/li&gt;
&lt;li&gt;$0 &#92;le L[i] &amp;lt; R[i] &amp;lt; n$&lt;/li&gt;
&lt;li&gt;$-10^5 &#92;le &#92;text{nums[i]} &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1424 - Diagonal Traverse II</title>
    <link href="http://oj.roy4801.tw/2023/11/22/leetcode/1424/"/>
    <id>http://oj.roy4801.tw/2023/11/22/leetcode/1424/</id>
    <published>2023-11-22T19:51:40.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/diagonal-traverse-ii/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/04/08/sample_1_1784.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個二維的整數陣列 &lt;code&gt;nums&lt;/code&gt; 問你能不能照對角順序輸出（左下到右上）。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1980 - Find Unique Binary String</title>
    <link href="http://oj.roy4801.tw/2023/11/16/leetcode/1980/"/>
    <id>http://oj.roy4801.tw/2023/11/16/leetcode/1980/</id>
    <published>2023-11-16T21:58:39.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-unique-binary-string/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 $n$ 個 binary string &lt;code&gt;nums&lt;/code&gt;，其中每個 string 長度 $n$，要你回傳沒有出現在 &lt;code&gt;nums&lt;/code&gt; 裏頭的 binary string。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 16$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
    <category term="map" scheme="http://oj.roy4801.tw/tags/map/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1846 - Maximum Element After Decreasing and Rearranging</title>
    <link href="http://oj.roy4801.tw/2023/11/15/leetcode/1846/"/>
    <id>http://oj.roy4801.tw/2023/11/15/leetcode/1846/</id>
    <published>2023-11-15T20:08:15.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-element-after-decreasing-and-rearranging/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個正整數陣列 &lt;code&gt;arr&lt;/code&gt; 問你能不能透過以下兩種操作變換成 &lt;code&gt;[1,2,3,...,i-1, i]&lt;/code&gt; 的遞增形式：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;對 &lt;code&gt;arr[i]&lt;/code&gt; 減一，不能小於等於零&lt;/li&gt;
&lt;li&gt;排列 &lt;code&gt;arr[i]&lt;/code&gt;&lt;br&gt;
以上操作可以做任意次，問經過操作後 &lt;code&gt;arr&lt;/code&gt; 滿足遞增形式的數字最多有幾個？&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2785 - Sort Vowels in a String</title>
    <link href="http://oj.roy4801.tw/2023/11/13/leetcode/2785/"/>
    <id>http://oj.roy4801.tw/2023/11/13/leetcode/2785/</id>
    <published>2023-11-13T21:08:24.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/sort-vowels-in-a-string/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 要你照規則排成新的字串 &lt;code&gt;t&lt;/code&gt; 並輸出：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;所有子音的字母保留原位&lt;/li&gt;
&lt;li&gt;所有母音照遞增排序&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2642 - Design Graph With Shortest Path Calculator</title>
    <link href="http://oj.roy4801.tw/2023/11/12/leetcode/2642/"/>
    <id>http://oj.roy4801.tw/2023/11/12/leetcode/2642/</id>
    <published>2023-11-12T00:35:06.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/design-graph-with-shortest-path-calculator/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/PfM8LXj.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;有一個有向帶權圖有 $n$ 個節點標號從 &lt;code&gt;0&lt;/code&gt; 到 &lt;code&gt;n-1&lt;/code&gt;，要你實作一個 &lt;code&gt;Graph&lt;/code&gt; class 可以輸入一張圖，包含 &lt;code&gt;n&lt;/code&gt; 個點和 &lt;code&gt;edges&lt;/code&gt; 邊，並且能提供求點 &lt;code&gt;a&lt;/code&gt; 到點 &lt;code&gt;b&lt;/code&gt; 的最短路徑，並且能隨時加邊。&lt;/p&gt;
&lt;p&gt;要實作三個 function:&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="dijkstra" scheme="http://oj.roy4801.tw/tags/dijkstra/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1743 - Restore the Array From Adjacent Pairs</title>
    <link href="http://oj.roy4801.tw/2023/11/11/leetcode/1743/"/>
    <id>http://oj.roy4801.tw/2023/11/11/leetcode/1743/</id>
    <published>2023-11-11T00:07:05.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/restore-the-array-from-adjacent-pairs/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 裏頭有 $n$ 個 unique 的元素。題目給你一個 &lt;code&gt;adjacentPairs[i] = [ui, vi]&lt;/code&gt; 陣列有 $n-1$ 個元素，代表 &lt;code&gt;ui&lt;/code&gt; 與 &lt;code&gt;vi&lt;/code&gt; 在 &lt;code&gt;nums&lt;/code&gt; 相鄰。保證所有 &lt;code&gt;nums&lt;/code&gt; 相鄰的數字一定出現在 &lt;code&gt;adjacentPairs&lt;/code&gt; 中，可能以任意順序出現。&lt;br&gt;
回傳原始的 &lt;code&gt;nums&lt;/code&gt; 陣列，如果有多種解，回傳任意一種。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;nums&lt;/code&gt; 長度: $2 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;&lt;code&gt;adjacentPairs&lt;/code&gt; 長度: $== n-1$&lt;/li&gt;
&lt;li&gt;$-10^5 &#92;le &#92;text{nums[i]}, u_i, v_i &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
    <category term="map" scheme="http://oj.roy4801.tw/tags/map/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1759 - Count Number of Homogenous Substrings</title>
    <link href="http://oj.roy4801.tw/2023/11/09/leetcode/1759/"/>
    <id>http://oj.roy4801.tw/2023/11/09/leetcode/1759/</id>
    <published>2023-11-09T19:25:06.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-number-of-homogenous-substrings&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 要你回傳所有 homogeneous 的子字串的個數總和。homogenous 指的是字串裡的所有字元都一樣。&lt;br&gt;
答案可能很大要 mod $10^9+7$&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1535 - Find the Winner of an Array Game</title>
    <link href="http://oj.roy4801.tw/2023/11/05/leetcode/1535/"/>
    <id>http://oj.roy4801.tw/2023/11/05/leetcode/1535/</id>
    <published>2023-11-05T19:14:16.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-winner-of-an-array-game/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個數字不重複的整數陣列 &lt;code&gt;arr&lt;/code&gt; 和一個整數 &lt;code&gt;k&lt;/code&gt;，每次比較陣列第一個(&lt;code&gt;arr[0]&lt;/code&gt;)與第二個元素(&lt;code&gt;arr[1]&lt;/code&gt;)的大小，贏的數字會在 index 0，輸的數字則移動到 &lt;code&gt;arr&lt;/code&gt; 的最後，其他數字依序往前移動一格。當有個數字連續贏 &lt;code&gt;k&lt;/code&gt; 場時比賽結束，回傳贏的數字。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le &#92;text{len(arr)} &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{arr[i]} &#92;le 10^6$&lt;/li&gt;
&lt;li&gt;$1 &#92;le k &#92;le 10^9$&lt;/li&gt;
&lt;li&gt;保證每場比賽一定會有贏者&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1503 - Last Moment Before All Ants Fall Out of a Plank</title>
    <link href="http://oj.roy4801.tw/2023/11/05/leetcode/1503/"/>
    <id>http://oj.roy4801.tw/2023/11/05/leetcode/1503/</id>
    <published>2023-11-05T00:43:40.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/last-moment-before-all-ants-fall-out-of-a-plank/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;木棍長 &lt;code&gt;n&lt;/code&gt; 個單位，上頭有一群螞蟻在走，各自朝著左方與右方，每秒移動一個單位。每當螞蟻相遇時，會各自往反方向走。當螞蟻走出 &lt;code&gt;0&lt;/code&gt; 或 &lt;code&gt;n&lt;/code&gt; 時會掉出去，給你朝左與朝右的螞蟻初始位置，問你經過幾秒後，所有螞蟻都掉出木棍?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1441 - Build an Array With Stack Operations</title>
    <link href="http://oj.roy4801.tw/2023/11/03/leetcode/1441/"/>
    <id>http://oj.roy4801.tw/2023/11/03/leetcode/1441/</id>
    <published>2023-11-03T20:47:55.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/build-an-array-with-stack-operations/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;你有一個 stack 並可以對他做兩個操作:&lt;code&gt;Push&lt;/code&gt;, &lt;code&gt;Pop&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;target&lt;/code&gt; 和整數 &lt;code&gt;n&lt;/code&gt; ，你有 &lt;code&gt;[1, n]&lt;/code&gt; 數字，每次 &lt;code&gt;Push&lt;/code&gt; 數字都會加一，問你能不能給出一組操作，使得 stack 的元素等於 &lt;code&gt;target&lt;/code&gt;？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="stack" scheme="http://oj.roy4801.tw/tags/stack/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2433 - Find The Original Array of Prefix Xor</title>
    <link href="http://oj.roy4801.tw/2023/10/31/leetcode/2433/"/>
    <id>http://oj.roy4801.tw/2023/10/31/leetcode/2433/</id>
    <published>2023-10-31T19:48:54.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-original-array-of-prefix-xor/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;pref&lt;/code&gt; 長度 &lt;code&gt;n&lt;/code&gt;，要你回傳一個新的陣列，滿足條件：&lt;code&gt;pref[i] = arr[0] ^ arr[1] ^ ... ^ arr[i]&lt;/code&gt;&lt;br&gt;
答案保證唯一。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$0 &#92;le val &#92;le 10^6$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1356 - Sort Integers by The Number of 1 Bits</title>
    <link href="http://oj.roy4801.tw/2023/10/30/leetcode/1356/"/>
    <id>http://oj.roy4801.tw/2023/10/30/leetcode/1356/</id>
    <published>2023-10-30T19:51:58.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/sort-integers-by-the-number-of-1-bits/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;arr&lt;/code&gt;，依照每個數字的 binary 數字&lt;code&gt;1&lt;/code&gt;出現的次數來&lt;strong&gt;遞增排序&lt;/strong&gt;並回傳。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;li&gt;$0 &#92;le val &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2917 - Find the K-or of an Array</title>
    <link href="http://oj.roy4801.tw/2023/10/29/leetcode/2917/"/>
    <id>http://oj.roy4801.tw/2023/10/29/leetcode/2917/</id>
    <published>2023-10-29T23:55:29.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-k-or-of-an-array/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 和整數 &lt;code&gt;k&lt;/code&gt; ， &lt;strong&gt;K-or&lt;/strong&gt; 代表每個 =1 的第 &lt;code&gt;i&lt;/code&gt; 個 bit 的數量有大於等於 &lt;code&gt;k&lt;/code&gt; 個的話，將第 &lt;code&gt;i&lt;/code&gt; 個 bit 的數值($2^i$)計入總和，&lt;br&gt;
題目要你回傳 &lt;code&gt;K-or&lt;/code&gt;。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 50$&lt;/li&gt;
&lt;li&gt;$1 &#92;le k &#92;le n$&lt;/li&gt;
&lt;li&gt;$0 &#92;le val &amp;lt; 2^{31}$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 515 - Find Largest Value in Each Tree Row</title>
    <link href="http://oj.roy4801.tw/2023/10/24/leetcode/515/"/>
    <id>http://oj.roy4801.tw/2023/10/24/leetcode/515/</id>
    <published>2023-10-24T20:00:42.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-largest-value-in-each-tree-row&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/08/21/largest_e1.jpg&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個二元樹，要你輸出每一層的最大值。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 342 - Power of Four</title>
    <link href="http://oj.roy4801.tw/2023/10/23/leetcode/342/"/>
    <id>http://oj.roy4801.tw/2023/10/23/leetcode/342/</id>
    <published>2023-10-23T19:51:32.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/power-of-four/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你整數 &lt;code&gt;n&lt;/code&gt; 如果 $n = 4^x$ 的話回傳 &lt;code&gt;true&lt;/code&gt; 反之回傳 &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Follow up: $O(1)$ 時間複雜度&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 341 - Flatten Nested List Iterator</title>
    <link href="http://oj.roy4801.tw/2023/10/20/leetcode/341/"/>
    <id>http://oj.roy4801.tw/2023/10/20/leetcode/341/</id>
    <published>2023-10-20T09:24:26.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/flatten-nested-list-iterator/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個介面 &lt;code&gt;NestedInteger&lt;/code&gt; 裡頭可以是單個整數、或是另一堆 &lt;code&gt;NextedInteger&lt;/code&gt; ，要你實作 &lt;code&gt;NestedIterator&lt;/code&gt; 提供方法可以遍歷 &lt;code&gt;NestedInteger&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;NestedIterator&lt;/code&gt; 共有三個 member function:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;code&gt;NestedIterator(List&amp;lt;NestedInteger&amp;gt; nestedList)&lt;/code&gt; 初始化&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int next()&lt;/code&gt; 回傳下個數字&lt;/li&gt;
&lt;li&gt;&lt;code&gt;boolean hasNext()&lt;/code&gt; 是否到盡頭了&lt;/li&gt;
&lt;/ol&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Class" scheme="http://oj.roy4801.tw/tags/Class/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1361 - Validate Binary Tree Nodes</title>
    <link href="http://oj.roy4801.tw/2023/10/18/leetcode/1361/"/>
    <id>http://oj.roy4801.tw/2023/10/18/leetcode/1361/</id>
    <published>2023-10-18T19:39:49.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/validate-binary-tree-nodes/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 &lt;code&gt;n&lt;/code&gt; 個二元樹的節點，對於節點 &lt;code&gt;i&lt;/code&gt; 有兩個小孩 &lt;code&gt;left[i]&lt;/code&gt; 和 &lt;code&gt;right[i]&lt;/code&gt; 分別代表左和右子節點，&lt;code&gt;-1&lt;/code&gt; 代表不存在，要你回傳判斷題目給的測資是否是一個二元樹&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 746 - Min Cost Climbing Stairs</title>
    <link href="http://oj.roy4801.tw/2023/10/14/leetcode/746/"/>
    <id>http://oj.roy4801.tw/2023/10/14/leetcode/746/</id>
    <published>2023-10-14T05:02:17.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/min-cost-climbing-stairs/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;cost[i]&lt;/code&gt; 代表踩第 &lt;code&gt;i&lt;/code&gt; 階樓梯的花費，每次可以跨一階或是兩階，從 &lt;code&gt;0&lt;/code&gt; 或是 &lt;code&gt;1&lt;/code&gt; 開始踩，問到頂樓的&lt;strong&gt;最小花費&lt;/strong&gt;是多少?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;樓梯階數: $2 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;li&gt;cost 值: $0 &#92;le val &#92;le 999$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1512 - Number of Good Pairs</title>
    <link href="http://oj.roy4801.tw/2023/10/03/leetcode/1512/"/>
    <id>http://oj.roy4801.tw/2023/10/03/leetcode/1512/</id>
    <published>2023-10-03T09:14:25.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/number-of-good-pairs/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 integer array &lt;code&gt;nums&lt;/code&gt; 要你回傳 good pair 的數量&lt;br&gt;
good pair: pair &lt;code&gt;(i, j)&lt;/code&gt; 是 good pair if &lt;code&gt;nums[i] == nums[j]&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n, val &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2038 - Remove Colored Pieces if Both Neighbors are the Same Color</title>
    <link href="http://oj.roy4801.tw/2023/10/02/leetcode/2038/"/>
    <id>http://oj.roy4801.tw/2023/10/02/leetcode/2038/</id>
    <published>2023-10-02T19:58:24.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-same-color/description/?envType=daily-question&amp;amp;envId=2023-10-02&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;n&lt;/code&gt; 個字母，由 &lt;code&gt;A&lt;/code&gt; 和 &lt;code&gt;B&lt;/code&gt; 字元組成 &lt;code&gt;colors[i]&lt;/code&gt; ，今天 Alice 和 Bob 交替從 &lt;code&gt;colors&lt;/code&gt; 刪除各自的代表色：Alice 是 &lt;code&gt;A&lt;/code&gt;、Bob 是 &lt;code&gt;B&lt;/code&gt;，由 Alice 先手。&lt;br&gt;
規則是只能刪除左右兩邊與自己相同的第 &lt;code&gt;i&lt;/code&gt; 個字元，如果一個玩家沒有東西可刪，則代表是輸家。如果 Alice 贏了則回傳 &lt;code&gt;true&lt;/code&gt;；否則回傳 &lt;code&gt;false&lt;/code&gt;。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Game Thoery" scheme="http://oj.roy4801.tw/tags/Game-Thoery/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 389 - Find the Difference</title>
    <link href="http://oj.roy4801.tw/2023/09/25/leetcode/389/"/>
    <id>http://oj.roy4801.tw/2023/09/25/leetcode/389/</id>
    <published>2023-09-25T19:31:39.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-difference/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s&lt;/code&gt; 和 &lt;code&gt;t&lt;/code&gt;，其中 &lt;code&gt;t&lt;/code&gt; 是由 &lt;code&gt;s&lt;/code&gt; 隨機 shuffle，其中 &lt;code&gt;t&lt;/code&gt; 比 &lt;code&gt;s&lt;/code&gt; 多一個字元&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$0 &#92;le siz &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1337 - The K Weakest Rows in a Matrix</title>
    <link href="http://oj.roy4801.tw/2023/09/18/leetcode/1337/"/>
    <id>http://oj.roy4801.tw/2023/09/18/leetcode/1337/</id>
    <published>2023-09-18T19:47:51.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 &lt;code&gt;mxn&lt;/code&gt; 的 matrix 其中每一列的 &lt;code&gt;1&lt;/code&gt; 代表士兵、&lt;code&gt;0&lt;/code&gt; 代表平民，所有的士兵都會在平民的左邊。&lt;br&gt;
其中，第 &lt;code&gt;i&lt;/code&gt; 列如果比第 &lt;code&gt;j&lt;/code&gt; 列還弱，代表：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;第 &lt;code&gt;i&lt;/code&gt; 列的士兵比第 &lt;code&gt;j&lt;/code&gt; 列的士兵數量還少&lt;/li&gt;
&lt;li&gt;如果士兵數量一樣，則 $i &amp;lt; j$&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;要你輸出前 &lt;code&gt;k&lt;/code&gt; 弱的列有哪些？&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1584 - Min Cost to Connect All Points</title>
    <link href="http://oj.roy4801.tw/2023/09/15/leetcode/1584/"/>
    <id>http://oj.roy4801.tw/2023/09/15/leetcode/1584/</id>
    <published>2023-09-15T19:41:30.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/min-cost-to-connect-all-points/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;points[i] = [x,y]&lt;/code&gt; 是在 2D 平面上的座標，令連接兩點的費用為兩點之間的曼哈頓距離(manhattan distance)&lt;br&gt;
問你把圖聯通後且每個點到另一個點都只有存在一條簡單路徑，最小要花費多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;li&gt;$-10^6 &#92;le x_i, y_i &#92;le 10^6$&lt;/li&gt;
&lt;li&gt;點不會重複&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="minumum spanning tree" scheme="http://oj.roy4801.tw/tags/minumum-spanning-tree/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1647 - Minimum Deletions to Make Character Frequencies Unique</title>
    <link href="http://oj.roy4801.tw/2023/09/12/leetcode/1647/"/>
    <id>http://oj.roy4801.tw/2023/09/12/leetcode/1647/</id>
    <published>2023-09-12T09:25:46.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/description/?envType=daily-question&amp;amp;envId=2023-09-12&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;令字母出現次數不重複的字串叫做好字串，問你今天給你一個字串，能夠最小刪除多少，使得字串變成好字串？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1282 - Group the People Given the Group Size They Belong To</title>
    <link href="http://oj.roy4801.tw/2023/09/11/leetcode/1282/"/>
    <id>http://oj.roy4801.tw/2023/09/11/leetcode/1282/</id>
    <published>2023-09-11T19:32:55.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 $n$ 個人要分組，給你一個整數陣列 &lt;code&gt;groupSizes&lt;/code&gt;，其中 &lt;code&gt;groupSizes[i]&lt;/code&gt; 代表第 $i$ 個人要待在大小 &lt;code&gt;groupSizes[i]&lt;/code&gt; 的組別，要你回傳最後分組的情況。&lt;br&gt;
限制：每個人只會在一個組內，如果有多組解，輸出一種即可，測資保證一定至少有一組解。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{groupSzie[i]} &#92;le n$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 92 - Reverse Linked List II</title>
    <link href="http://oj.roy4801.tw/2023/09/07/leetcode/92/"/>
    <id>http://oj.roy4801.tw/2023/09/07/leetcode/92/</id>
    <published>2023-09-07T20:20:57.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/reverse-linked-list-ii/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 linked-list 和兩個正整數 &lt;code&gt;left&lt;/code&gt; 和 &lt;code&gt;right&lt;/code&gt;，代表位置(1-index)，要你把位置 &lt;code&gt;left&lt;/code&gt; 到 &lt;code&gt;right&lt;/code&gt; 的 node 反轉，最後回傳整個 linked-list&lt;/p&gt;
&lt;p&gt;follow-up: 1-pass 要做完&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2483 - Minimum Penalty for a Shop</title>
    <link href="http://oj.roy4801.tw/2023/08/29/leetcode/2483/"/>
    <id>http://oj.roy4801.tw/2023/08/29/leetcode/2483/</id>
    <published>2023-08-29T22:36:57.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-penalty-for-a-shop/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個由 &lt;code&gt;Y&lt;/code&gt; 和 &lt;code&gt;N&lt;/code&gt; 組成的字串 &lt;code&gt;customers&lt;/code&gt; 其中第 $i$ 個字元 &lt;code&gt;customers[i]&lt;/code&gt; 代表第 $i$ 個小時有沒有客人來&lt;br&gt;
令 $j$ 等於關店的時間，有兩條規則：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;如果店開著的時候沒有客人來的話，扣一點&lt;/li&gt;
&lt;li&gt;如果有客人在店關了之後來的話，扣一點&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;問你能不能回傳最早的小時，其扣點最大？&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="prefix sum" scheme="http://oj.roy4801.tw/tags/prefix-sum/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 225 - Implement Stack using Queues</title>
    <link href="http://oj.roy4801.tw/2023/08/28/leetcode/225/"/>
    <id>http://oj.roy4801.tw/2023/08/28/leetcode/225/</id>
    <published>2023-08-28T19:25:11.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/implement-stack-using-queues/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;要你用兩個 queue 去實作 stack&lt;/p&gt;
&lt;p&gt;follow-up: 可不可以只用一個 queue&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 215 - Kth Largest Element in an Array</title>
    <link href="http://oj.roy4801.tw/2023/08/14/leetcode/215/"/>
    <id>http://oj.roy4801.tw/2023/08/14/leetcode/215/</id>
    <published>2023-08-14T21:29:03.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/kth-largest-element-in-an-array/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 和整數 &lt;code&gt;k&lt;/code&gt;，要你回傳 &lt;code&gt;nums&lt;/code&gt; 中第 &lt;code&gt;k&lt;/code&gt; 大的整數&lt;br&gt;
限制: 不能用 sort&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le k &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$-10^4 &#92;le val &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 74 -  Search a 2D Matrix</title>
    <link href="http://oj.roy4801.tw/2023/08/07/leetcode/74/"/>
    <id>http://oj.roy4801.tw/2023/08/07/leetcode/74/</id>
    <published>2023-08-07T19:49:52.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/search-a-2d-matrix/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 &lt;code&gt;nxm&lt;/code&gt; 的矩陣，問你能不能找到 &lt;code&gt;target&lt;/code&gt; 在哪一個行哪一列?&lt;br&gt;
其中每一列都是由小到大排序的，第 $i+1$ 列的第一個大於第 $i$ 列的最後一個數字&lt;/p&gt;
&lt;p&gt;實作複雜度限制在: $O(&#92;log{nm})$&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 139 - Word Break</title>
    <link href="http://oj.roy4801.tw/2023/08/05/leetcode/139/"/>
    <id>http://oj.roy4801.tw/2023/08/05/leetcode/139/</id>
    <published>2023-08-05T03:00:52.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/word-break/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 和一個字典 &lt;code&gt;wordDict&lt;/code&gt;，問你能不能把 &lt;code&gt;s&lt;/code&gt; 切成多個出現在字典裏頭的單字，可以的話回傳 &lt;code&gt;true&lt;/code&gt;&lt;br&gt;
字串 &lt;code&gt;s&lt;/code&gt; 全部切完一定都要出現在字典中，字典中的單字可以在切完的字串中重複出現&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;字串長度: $1 &#92;le n &#92;le 300$&lt;/li&gt;
&lt;li&gt;字典大小: $1 &#92;le m &#92;le 1000$&lt;/li&gt;
&lt;li&gt;字典裡字串長度: $1 &#92;le m_i &#92;le 20$&lt;/li&gt;
&lt;li&gt;只會出現小寫，且字典不會出現重複的字串&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 46 - Permutations</title>
    <link href="http://oj.roy4801.tw/2023/08/02/leetcode/46/"/>
    <id>http://oj.roy4801.tw/2023/08/02/leetcode/46/</id>
    <published>2023-08-02T09:36:18.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/permutations/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一堆數字 &lt;code&gt;nums&lt;/code&gt; 要你輸出它的全排序，可以以任何順序輸出&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 6$&lt;/li&gt;
&lt;li&gt;$-10 &#92;le val &#92;le 10$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 77 - Combinations</title>
    <link href="http://oj.roy4801.tw/2023/08/01/leetcode/77/"/>
    <id>http://oj.roy4801.tw/2023/08/01/leetcode/77/</id>
    <published>2023-08-01T20:03:53.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/combinations/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個數字 $n$ 和 $k$ 問你能不能回傳從 $[1, n]$ 中挑 $k$ 個數字的所有組合&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 20$&lt;/li&gt;
&lt;li&gt;$1 &#92;le k &#92;le n$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1870 - Minimum Speed to Arrive on Time</title>
    <link href="http://oj.roy4801.tw/2023/07/26/leetcode/1870/"/>
    <id>http://oj.roy4801.tw/2023/07/26/leetcode/1870/</id>
    <published>2023-07-26T19:54:04.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-speed-to-arrive-on-time/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;可以花 &lt;code&gt;hour&lt;/code&gt; 小時通勤到辦公室，必須要按照順序搭繩 &lt;code&gt;n&lt;/code&gt; 輛火車，並給你 &lt;code&gt;dist[i]&lt;/code&gt; 長度 &lt;code&gt;n&lt;/code&gt; 代表第 &lt;code&gt;i&lt;/code&gt; 輛火車要搭幾公里&lt;br&gt;
每輛列車必須在整點出發，問你能不能回傳一個最小的速度搭完所有的火車，回傳 &lt;code&gt;-1&lt;/code&gt; 代表不可能準時到達。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le dist[i] &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le hour &#92;le 10^9$&lt;/li&gt;
&lt;li&gt;保證答案不超過 $10^7$，且 &lt;code&gt;hour&lt;/code&gt; 會給到小數第二位&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
    <category term="二分答案" scheme="http://oj.roy4801.tw/tags/%E4%BA%8C%E5%88%86%E7%AD%94%E6%A1%88/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 735 - Asteroid Collision</title>
    <link href="http://oj.roy4801.tw/2023/07/20/leetcode/735/"/>
    <id>http://oj.roy4801.tw/2023/07/20/leetcode/735/</id>
    <published>2023-07-20T19:48:41.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/asteroid-collision/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;asteroids&lt;/code&gt; 其中的數字正負代表方向(正=右，負=左)，數值的絕對值代表大小&lt;br&gt;
每個小行星沿著各自的方向運動，速度相同。方向相對的發生碰撞；方向相反則永遠不會發生碰撞。發生相撞時大的留下來，小的則消失，如果大小相同則兩個都消失。&lt;br&gt;
問你撞到最後，留下來的有哪些？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;li&gt;$-1000 &#92;le val &#92;le 1000, val &#92;neq 0$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="stack" scheme="http://oj.roy4801.tw/tags/stack/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 445 - Add Two Numbers II</title>
    <link href="http://oj.roy4801.tw/2023/07/17/leetcode/445/"/>
    <id>http://oj.roy4801.tw/2023/07/17/leetcode/445/</id>
    <published>2023-07-17T20:16:24.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/add-two-numbers-ii/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/04/09/sumii-linked-list.jpg&quot; height=&quot;50%&quot;&gt;
&lt;p&gt;給你兩個 &lt;code&gt;linked-list&lt;/code&gt; 問你相加回傳多少&lt;/p&gt;
&lt;p&gt;Follow-up: 在不 reverse input 的情況下解這題&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2779 - Maximum Beauty of an Array After Applying Operation</title>
    <link href="http://oj.roy4801.tw/2023/07/16/leetcode/2779/"/>
    <id>http://oj.roy4801.tw/2023/07/16/leetcode/2779/</id>
    <published>2023-07-16T23:07:41.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;nums&lt;/code&gt;和一個非負整數 &lt;code&gt;k&lt;/code&gt;，你可以做以下操作&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;挑一個數字 $nums[i]$ 其中 $i &#92;in [0, n-1]$&lt;/li&gt;
&lt;li&gt;將 $nums[i]$ 換成 $[nums[i] - k, nums[i] + k]$ 其中的數字&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;定義一個 array 的美麗值(Beauty)為「相同數字」的最長子序列，問你回傳最大的 beauty 值為多少?&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="interval" scheme="http://oj.roy4801.tw/tags/interval/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2778 - Sum of Squares of Special Elements</title>
    <link href="http://oj.roy4801.tw/2023/07/16/leetcode/2778/"/>
    <id>http://oj.roy4801.tw/2023/07/16/leetcode/2778/</id>
    <published>2023-07-16T22:56:28.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/sum-of-squares-of-special-elements/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 &lt;code&gt;1-index&lt;/code&gt; 的陣列 &lt;code&gt;nums&lt;/code&gt; 長度 $n$，對於 $nums[i]$ 滿足 &lt;code&gt;n % i == 0&lt;/code&gt; 為特殊數字&lt;br&gt;
回傳所有特殊數字的平方和&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n, val &#92;le 50$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 207 - Course Schedule</title>
    <link href="http://oj.roy4801.tw/2023/07/13/leetcode/207/"/>
    <id>http://oj.roy4801.tw/2023/07/13/leetcode/207/</id>
    <published>2023-07-13T21:50:49.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/course-schedule/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個正整數 $n$ 代表課程數量(從 &lt;code&gt;0`` 到 &lt;/code&gt;n-1&lt;code&gt;)，並給你一個 &lt;/code&gt;prerequisites[i] = [a_i, b_i] (int[m][2])&lt;code&gt;的陣列，代表如果要上課程&lt;/code&gt;b_i&lt;code&gt;，一定要先上課程 &lt;/code&gt;a_i`&lt;br&gt;
問你能不能上完所有課程?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 2000$&lt;/li&gt;
&lt;li&gt;$0 &#92;le m &#92;le 5000$&lt;/li&gt;
&lt;li&gt;$(a_i, b_i)$ 不重複&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="cycle" scheme="http://oj.roy4801.tw/tags/cycle/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 863 - All Nodes Distance K in Binary Tree</title>
    <link href="http://oj.roy4801.tw/2023/07/11/leetcode/863/"/>
    <id>http://oj.roy4801.tw/2023/07/11/leetcode/863/</id>
    <published>2023-07-11T19:39:37.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/all-nodes-distance-k-in-binary-tree/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個二元樹，和目標節點(&lt;code&gt;target&lt;/code&gt;）以及一個正整數 &lt;code&gt;k&lt;/code&gt; ，要你回傳所有與 &lt;code&gt;target&lt;/code&gt; 距離 &lt;code&gt;k&lt;/code&gt; 的節點&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;number of nodes: $0 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;li&gt;$0 &#92;le k &#92;le 1000$$&lt;/li&gt;
&lt;li&gt;node value: $0 &#92;le val &#92;le 500$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="bfs" scheme="http://oj.roy4801.tw/tags/bfs/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 111 - Minimum Depth of Binary Tree</title>
    <link href="http://oj.roy4801.tw/2023/07/10/leetcode/111/"/>
    <id>http://oj.roy4801.tw/2023/07/10/leetcode/111/</id>
    <published>2023-07-10T19:27:49.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-depth-of-binary-tree/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 binary tree 問你 minimum depth 是多少?&lt;br&gt;
minimum depth 為根節點(Root)到最近的葉節點(Leaf)的深度&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$0 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="bfs" scheme="http://oj.roy4801.tw/tags/bfs/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 209 - Minimum Size Subarray Sum</title>
    <link href="http://oj.roy4801.tw/2023/07/06/leetcode/209/"/>
    <id>http://oj.roy4801.tw/2023/07/06/leetcode/209/</id>
    <published>2023-07-06T20:25:51.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-size-subarray-sum/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個正整數陣列 &lt;code&gt;nums&lt;/code&gt; 和一個正整數 &lt;code&gt;target&lt;/code&gt;，要求 subarray 總和不超過 &lt;code&gt;target&lt;/code&gt; ，要你回傳 subarray 最小的長度，如果找不到則回傳 &lt;code&gt;0&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le target &#92;le 10^9$&lt;/li&gt;
&lt;li&gt;$1 &#92;le nums &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le nums[i] &#92;le 10^4$$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sliding window" scheme="http://oj.roy4801.tw/tags/sliding-window/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1493 - Longest Subarray of 1&#39;s After Deleting One Element</title>
    <link href="http://oj.roy4801.tw/2023/07/05/leetcode/1493/"/>
    <id>http://oj.roy4801.tw/2023/07/05/leetcode/1493/</id>
    <published>2023-07-05T20:30:22.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個只有 &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;1&lt;/code&gt; 的 array &lt;code&gt;nums&lt;/code&gt;，你會從中刪除一個元素&lt;br&gt;
問你刪完之後，只包含 &lt;code&gt;1&lt;/code&gt; 的最長的 subarray 長度多少？ 沒有的話回傳 &lt;code&gt;0&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$&#92;text{nums[i]} &#92;in {0,1}$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sliding window" scheme="http://oj.roy4801.tw/tags/sliding-window/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 859 - Buddy Strings</title>
    <link href="http://oj.roy4801.tw/2023/07/03/leetcode/859/"/>
    <id>http://oj.roy4801.tw/2023/07/03/leetcode/859/</id>
    <published>2023-07-03T22:43:42.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/buddy-strings/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s&lt;/code&gt; 和 &lt;code&gt;goal&lt;/code&gt; 問你可不可以交換兩個字元的方式來把 &lt;code&gt;s&lt;/code&gt; 變成 &lt;code&gt;goal&lt;/code&gt;&lt;br&gt;
交換字元: 給兩個 index $i$ 和 $j$ 且 $i &#92;neq j$ ，交換 &lt;code&gt;s[i]&lt;/code&gt; 和 &lt;code&gt;goal[j]&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le s, goal &#92;le 2&#92;cdot 10^4$&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt;, &lt;code&gt;goal&lt;/code&gt; are lowercase&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2305 - Fair Distribution of Cookies</title>
    <link href="http://oj.roy4801.tw/2023/07/01/leetcode/2305/"/>
    <id>http://oj.roy4801.tw/2023/07/01/leetcode/2305/</id>
    <published>2023-07-01T23:15:21.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/fair-distribution-of-cookies/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;cookies&lt;/code&gt; 代表餅乾的數量和一個正整數 &lt;code&gt;k&lt;/code&gt; 代表人的個數，今天要把這些餅乾全部分給這些人，要拿一次就拿 &lt;code&gt;cookies[i]&lt;/code&gt; 個，不能分割。&lt;br&gt;
令&lt;strong&gt;公平值&lt;/strong&gt;為一個人拿到的餅乾數量總和，要你回傳最小可能的&lt;strong&gt;公平值&lt;/strong&gt;是多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le c &#92;le 8$&lt;/li&gt;
&lt;li&gt;$1 &#92;le c[i] &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$2 &#92;le k &#92;le c$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>CSES 1071 - Number Spiral</title>
    <link href="http://oj.roy4801.tw/2023/06/23/cses/1071/"/>
    <id>http://oj.roy4801.tw/2023/06/23/cses/1071/</id>
    <published>2023-06-23T01:02:21.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://cses.fi/problemset/task/1071&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://hackmd.io/_uploads/BJyBJZMdn.png&quot; width=&quot;25%&quot;&gt;
&lt;p&gt;有個無限大的格子，最左上角開始的數字是 $1$，上圖展示了它的前五層數字，可以發現是螺旋往外的&lt;/p&gt;
&lt;p&gt;題目問給你 row $y$ 和 column $x$ 要你回傳那格的數字&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="CSES" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/CSES/"/>
    
    <category term="Introductory Problems" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/CSES/Introductory-Problems/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="CSES" scheme="http://oj.roy4801.tw/tags/CSES/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2090 - K Radius Subarray Averages</title>
    <link href="http://oj.roy4801.tw/2023/06/20/leetcode/2090/"/>
    <id>http://oj.roy4801.tw/2023/06/20/leetcode/2090/</id>
    <published>2023-06-20T21:55:08.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/k-radius-subarray-averages/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/11/07/eg1.png&quot; width=&quot;50%&quot;&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 有 $n$ 個數字，和一個整數 $k$。對於 index $i$ 能覆蓋 $[i-k, i+k]$ 範圍，其範圍內的平均數為 $avg[i]$ 問你能不能求出這個陣列&lt;br&gt;
如果涵蓋的範圍比 $n$ 大 ($2 &#92;times k + 1 &amp;gt; n$) 或是其中超出 n 的 index ($i &amp;lt; 0$ or $i &#92;ge n$)，則該 $avg[i] = -1$&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="prefix sum" scheme="http://oj.roy4801.tw/tags/prefix-sum/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>CSES 1068 - Weird Algorithm</title>
    <link href="http://oj.roy4801.tw/2023/06/19/cses/1068/"/>
    <id>http://oj.roy4801.tw/2023/06/19/cses/1068/</id>
    <published>2023-06-19T22:29:13.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://cses.fi/problemset/task/1068&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個正整數 $n$，如果 $n$ 是偶數則除 $2$；如果 $n$ 是奇數則乘以 $3$ 加上 $1$，一直做下去直到變成 $1$&lt;br&gt;
問你數字的變化過程&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 10^6$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="CSES" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/CSES/"/>
    
    <category term="Introductory Problems" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/CSES/Introductory-Problems/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="CSES" scheme="http://oj.roy4801.tw/tags/CSES/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1732 - Find the Highest Altitude</title>
    <link href="http://oj.roy4801.tw/2023/06/19/leetcode/1732/"/>
    <id>http://oj.roy4801.tw/2023/06/19/leetcode/1732/</id>
    <published>2023-06-19T21:03:41.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-highest-altitude/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一個人從 &lt;code&gt;0&lt;/code&gt; 開始往上走，給你一個 &lt;code&gt;gain&lt;/code&gt; 整數陣列，其中 &lt;code&gt;gain[i]&lt;/code&gt; 代表 &lt;code&gt;i&lt;/code&gt; 與 &lt;code&gt;i+1&lt;/code&gt; 的相差，問你他走完全程，途中最大的高度是多少?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;$-100 &#92;le &#92;text{gain}[i] &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1161 - Maximum Level Sum of a Binary Tree</title>
    <link href="http://oj.roy4801.tw/2023/06/15/leetcode/1161/"/>
    <id>http://oj.roy4801.tw/2023/06/15/leetcode/1161/</id>
    <published>2023-06-15T19:56:24.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-level-sum-of-a-binary-tree/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2019/05/03/capture.JPG&quot; width=&quot;50%&quot;&gt;
&lt;p&gt;給你一個 Binary Tree 問你能不能回傳一個&lt;strong&gt;最小&lt;/strong&gt;的 depth $x$ 其中 depth $x$ 的所有 node 總和 $y$ &lt;strong&gt;最大&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="BFS" scheme="http://oj.roy4801.tw/tags/BFS/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 530 - Minimum Absolute Difference in BST</title>
    <link href="http://oj.roy4801.tw/2023/06/14/leetcode/530/"/>
    <id>http://oj.roy4801.tw/2023/06/14/leetcode/530/</id>
    <published>2023-06-14T20:11:38.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-absolute-difference-in-bst/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/02/05/bst1.jpg&quot; width=&quot;50%&quot;&gt;
&lt;p&gt;給你一個二元搜尋樹(Binary Search Tree, BST)，問你樹上所有點相差最小的是多少？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 744 - Find Smallest Letter Greater Than Target</title>
    <link href="http://oj.roy4801.tw/2023/06/10/leetcode/744/"/>
    <id>http://oj.roy4801.tw/2023/06/10/leetcode/744/</id>
    <published>2023-06-10T01:01:32.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-smallest-letter-greater-than-target/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 $n$ 個遞增排序的字元，要你找第一個大於 &lt;code&gt;target&lt;/code&gt; 的字元是啥&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^4$&lt;/li&gt;
&lt;li&gt;字元都是小寫、遞增排序&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1351 - Count Negative Numbers in a Sorted Matrix</title>
    <link href="http://oj.roy4801.tw/2023/06/09/leetcode/1351/"/>
    <id>http://oj.roy4801.tw/2023/06/09/leetcode/1351/</id>
    <published>2023-06-09T01:13:53.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 &lt;code&gt;mxn&lt;/code&gt; 的二維陣列，每列是遞減排序(non-increasing order)，要你會傳總共有幾個負整數?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le m,n &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1318 - Minimum Flips to Make a OR b Equal to c</title>
    <link href="http://oj.roy4801.tw/2023/06/07/leetcode/1318/"/>
    <id>http://oj.roy4801.tw/2023/06/07/leetcode/1318/</id>
    <published>2023-06-07T19:23:15.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-flips-to-make-a-or-b-equal-to-c/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你三個正整數 &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt;，問你最少 flip &lt;code&gt;a&lt;/code&gt; 或 &lt;code&gt;b&lt;/code&gt; 幾次，使得 &lt;code&gt;a or b == c&lt;/code&gt;？&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le a, b, c &#92;le 10^9$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1502 - Can Make Arithmetic Progression From Sequence</title>
    <link href="http://oj.roy4801.tw/2023/06/06/leetcode/1502/"/>
    <id>http://oj.roy4801.tw/2023/06/06/leetcode/1502/</id>
    <published>2023-06-06T20:26:48.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;arr&lt;/code&gt; 問你陣列相連的元素相減是否都是一樣&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;li&gt;$-10^6 &#92;le arr[i] &#92;le 10^6$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2101 - Detonate the Maximum Bombs</title>
    <link href="http://oj.roy4801.tw/2023/06/05/leetcode/2101/"/>
    <id>http://oj.roy4801.tw/2023/06/05/leetcode/2101/</id>
    <published>2023-06-05T23:26:08.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/detonate-the-maximum-bombs/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/11/06/desmos-eg-3.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你 $n$ 個炸彈， &lt;code&gt;bomb[i] = (x, y, r)&lt;/code&gt;，你可以選擇一枚炸彈引爆，爆炸後在範圍內的炸彈會產生連鎖反應，問你最多一次能炸幾枚炸彈?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="BFS" scheme="http://oj.roy4801.tw/tags/BFS/"/>
    
    <category term="geometry" scheme="http://oj.roy4801.tw/tags/geometry/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1232 - Check If It Is a Straight Line</title>
    <link href="http://oj.roy4801.tw/2023/06/05/leetcode/1232/"/>
    <id>http://oj.roy4801.tw/2023/06/05/leetcode/1232/</id>
    <published>2023-06-05T21:15:04.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/check-if-it-is-a-straight-line/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;n&lt;/code&gt; 個座標 &lt;code&gt;coordinate[i] = (x, y)&lt;/code&gt;，問你能不能組成一條直線&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 1000$&lt;/li&gt;
&lt;li&gt;$-10^4 &#92;le x, y &#92;le 10^4 $&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 547 - Number of Provinces</title>
    <link href="http://oj.roy4801.tw/2023/06/04/leetcode/547/"/>
    <id>http://oj.roy4801.tw/2023/06/04/leetcode/547/</id>
    <published>2023-06-04T20:19:04.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/number-of-provinces/description&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 &lt;code&gt;n&lt;/code&gt; 個城市，給你 &lt;code&gt;nxn&lt;/code&gt; 的 &lt;code&gt;isConnected&lt;/code&gt; 其中 &lt;code&gt;isConnected[i][j] = 1&lt;/code&gt; 代表 &lt;code&gt;i&lt;/code&gt; 和 &lt;code&gt;j&lt;/code&gt; 相連；反之，則不相連。&lt;br&gt;
&lt;code&gt;province&lt;/code&gt; 指的是一組直接、間接相連的一群城市，問你總共有幾個 &lt;code&gt;province&lt;/code&gt;?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 200$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="disjoint set" scheme="http://oj.roy4801.tw/tags/disjoint-set/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1091 - Shortest Path in Binary Matrix</title>
    <link href="http://oj.roy4801.tw/2023/06/01/leetcode/1091/"/>
    <id>http://oj.roy4801.tw/2023/06/01/leetcode/1091/</id>
    <published>2023-06-01T23:29:14.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/shortest-path-in-binary-matrix/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/02/18/example2_1.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個 $n &#92;times n$ 只含 &lt;code&gt;0&lt;/code&gt; 和 &lt;code&gt;1&lt;/code&gt; 的矩陣 &lt;code&gt;grid&lt;/code&gt; 問你從左上 &lt;code&gt;(0, 0)&lt;/code&gt; 到右下 &lt;code&gt;(n-1, n-1)&lt;/code&gt; 走 &lt;code&gt;0&lt;/code&gt; 的最短路徑為何?&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="BFS" scheme="http://oj.roy4801.tw/tags/BFS/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1396 - Design Underground System</title>
    <link href="http://oj.roy4801.tw/2023/05/31/leetcode/1396/"/>
    <id>http://oj.roy4801.tw/2023/05/31/leetcode/1396/</id>
    <published>2023-05-31T21:07:08.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/design-underground-system/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;問你能不能實作一個地鐵乘客系統，紀錄乘客上、下車時間，並可以用來統計站與站之間的平均搭乘時間。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;void checkIn(int id, string stationName, int t)&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;乘客 &lt;code&gt;id&lt;/code&gt; 在時間 &lt;code&gt;t&lt;/code&gt; 在 &lt;code&gt;stationName&lt;/code&gt; 上車&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;void checkOut(int id, string stationName, int t)&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;乘客 &lt;code&gt;id&lt;/code&gt; 在時間 &lt;code&gt;t&lt;/code&gt; 在 &lt;code&gt;stationName&lt;/code&gt; 下車&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;double getAverageTime(string startStation, string endStation)&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;回傳從 &lt;code&gt;startStation&lt;/code&gt; 到 &lt;code&gt;endStation&lt;/code&gt; 的平均搭乘時間&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ol&gt;
&lt;li&gt;從 &lt;code&gt;start&lt;/code&gt; 到 &lt;code&gt;end&lt;/code&gt; 與 &lt;code&gt;end&lt;/code&gt; 到 &lt;code&gt;start&lt;/code&gt; 的時間可能不同&lt;/li&gt;
&lt;li&gt;在 &lt;code&gt;getAverageTime()&lt;/code&gt; 呼叫前一定至少會有一組 &lt;code&gt;start&lt;/code&gt; 與 &lt;code&gt;end&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;成對的 &lt;code&gt;checkIn&lt;/code&gt; 與 &lt;code&gt;checkOut&lt;/code&gt; 才會被算進平均時間中&lt;/li&gt;
&lt;/ol&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="Design" scheme="http://oj.roy4801.tw/tags/Design/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1603 - Design Parking System</title>
    <link href="http://oj.roy4801.tw/2023/05/29/leetcode/1603/"/>
    <id>http://oj.roy4801.tw/2023/05/29/leetcode/1603/</id>
    <published>2023-05-29T09:04:53.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/design-parking-system/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;要你實作一個 class 叫做 &lt;code&gt;ParkingSystem&lt;/code&gt; 代表個停車場，可以停三種大小的車：大、中、小，並有個 function 可以把車停入&lt;br&gt;
如果停得進去則回傳 &lt;code&gt;true&lt;/code&gt; 反之回傳 &lt;code&gt;false&lt;/code&gt;。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ParkingSystem(int big, int medium, int small)&lt;/code&gt;: 大、中、小車位數量&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bool addCar(int carType)&lt;/code&gt;: 停車，&lt;code&gt;carType&lt;/code&gt; 代表車子大小: 大1, 中2, 小3&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;&lt;span id=&quot;ce-zi-xian-zhi&quot;&gt;測資限制&lt;/span&gt;&lt;a href=&quot;#ce-zi-xian-zhi&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Design" scheme="http://oj.roy4801.tw/tags/Design/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1547 - Minimum Cost to Cut a Stick</title>
    <link href="http://oj.roy4801.tw/2023/05/28/leetcode/1547/"/>
    <id>http://oj.roy4801.tw/2023/05/28/leetcode/1547/</id>
    <published>2023-05-28T18:32:45.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-cost-to-cut-a-stick/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;時間複雜度: $&#92;mathcal{O}()$&lt;/li&gt;
&lt;li&gt;空間複雜度: $&#92;mathcal{O}()$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 703 - Kth Largest Element in a Stream</title>
    <link href="http://oj.roy4801.tw/2023/05/23/leetcode/703/"/>
    <id>http://oj.roy4801.tw/2023/05/23/leetcode/703/</id>
    <published>2023-05-23T21:13:10.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/kth-largest-element-in-a-stream/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;問你能不能設計一個 class 來在一個 stream 中找到第 &lt;code&gt;k&lt;/code&gt; 大的元素。&lt;/p&gt;
&lt;p&gt;你要實作兩個 function:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;KthLargest(int k, int[] nums)&lt;/code&gt; ctor 用來初始化 &lt;code&gt;k&lt;/code&gt; 和一開始的數字 &lt;code&gt;nums&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;int add(int val)&lt;/code&gt; 將 &lt;code&gt;val&lt;/code&gt; 加到資料中，你的 class 應能維護現在第 &lt;code&gt;k&lt;/code&gt; 大的數字並回傳&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Design" scheme="http://oj.roy4801.tw/tags/Design/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 347 - Top K Frequent Elements</title>
    <link href="http://oj.roy4801.tw/2023/05/22/leetcode/347/"/>
    <id>http://oj.roy4801.tw/2023/05/22/leetcode/347/</id>
    <published>2023-05-22T17:05:49.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/top-k-frequent-elements/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 和整數 &lt;code&gt;k&lt;/code&gt; ，要你回傳前 &lt;code&gt;k&lt;/code&gt; 多出現次數的數字，回傳任意順序即可&lt;/p&gt;
&lt;p&gt;follow-up: 請實作時間複雜度在 $O(n&#92;log{n})$&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le N &#92;le 10^5$ (&lt;code&gt;N=nums.size()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;$-10^4 &#92;le N[i] &#92;le 10^4$&lt;/li&gt;
&lt;li&gt;$1 &#92;le k &#92;le N$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 399 - Evaluate Division</title>
    <link href="http://oj.roy4801.tw/2023/05/20/leetcode/399/"/>
    <id>http://oj.roy4801.tw/2023/05/20/leetcode/399/</id>
    <published>2023-05-20T18:22:15.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/evaluate-division/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 string 陣列 &lt;code&gt;equations&lt;/code&gt; 和 double 陣列 &lt;code&gt;value&lt;/code&gt;，其中 &lt;code&gt;equations[i] = &amp;#123;A_i, B_i&amp;#125;&lt;/code&gt; 和 &lt;code&gt;values[i]&lt;/code&gt; 代表 &lt;code&gt;A_i / B_i = values[i]&lt;/code&gt;&lt;br&gt;
接著給你 &lt;code&gt;query&lt;/code&gt; 陣列，其中 &lt;code&gt;query[j] = &amp;#123;C_j, D_j&amp;#125;&lt;/code&gt; 代表要查詢 &lt;code&gt;C_j / D_j&lt;/code&gt; 是多少&lt;br&gt;
回傳所有的答案，如果答案找不到則回傳 &lt;code&gt;-1.0&lt;/code&gt; 即可&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le &#92;text{len(equations)} = &#92;text{len(values)} &#92;le 20$&lt;/li&gt;
&lt;li&gt;$0.0 &#92;le values[i] &#92;le 20.0$&lt;/li&gt;
&lt;li&gt;$1 &#92;le &#92;text{len(queries)} &#92;le 20$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2130 - Maximum Twin Sum of a Linked List</title>
    <link href="http://oj.roy4801.tw/2023/05/17/leetcode/2130/"/>
    <id>http://oj.roy4801.tw/2023/05/17/leetcode/2130/</id>
    <published>2023-05-17T20:02:38.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-twin-sum-of-a-linked-list/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/12/03/eg1drawio.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個 linked-list 有 &lt;code&gt;n&lt;/code&gt; 個點，切一半兩兩配對相加，問你相加最大多少？&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$n$ is even number&lt;/li&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 59 - Spiral Matrix II</title>
    <link href="http://oj.roy4801.tw/2023/05/10/leetcode/59/"/>
    <id>http://oj.roy4801.tw/2023/05/10/leetcode/59/</id>
    <published>2023-05-10T19:47:37.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/spiral-matrix-ii/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 $n &#92;times n$ 的矩陣，要你按照螺旋順序填數字並回傳&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 20$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 54 - Spiral Matrix</title>
    <link href="http://oj.roy4801.tw/2023/05/09/leetcode/54/"/>
    <id>http://oj.roy4801.tw/2023/05/09/leetcode/54/</id>
    <published>2023-05-09T23:22:04.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/spiral-matrix/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/11/13/spiral1.jpg&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個 $n &#92;times m$ 的矩陣，要你以迴旋順序回傳&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le m, n &#92;le 10$&lt;/li&gt;
&lt;li&gt;$-100 &#92;le M[i] &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="simulation" scheme="http://oj.roy4801.tw/tags/simulation/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1572 - Matrix Diagonal Sum</title>
    <link href="http://oj.roy4801.tw/2023/05/08/leetcode/1572/"/>
    <id>http://oj.roy4801.tw/2023/05/08/leetcode/1572/</id>
    <published>2023-05-08T09:09:26.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/matrix-diagonal-sum/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/08/14/sample_1911.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個矩陣 &lt;code&gt;mat&lt;/code&gt; 要你回傳對角的總和，重複的只要加一次就好&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;$mat = nxn$&lt;/li&gt;
&lt;li&gt;$1 &#92;le mat[i][j] &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1456 - Maximum Number of Vowels in a Substring of Given Length</title>
    <link href="http://oj.roy4801.tw/2023/05/05/leetcode/1456/"/>
    <id>http://oj.roy4801.tw/2023/05/05/leetcode/1456/</id>
    <published>2023-05-05T21:19:47.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 和一個正整數 &lt;code&gt;k&lt;/code&gt; ，問你 &lt;code&gt;s&lt;/code&gt; 的長度 &lt;code&gt;k&lt;/code&gt; 的所有子字串中，其中母音的數量最大是多少？&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le s, k &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sliding window" scheme="http://oj.roy4801.tw/tags/sliding-window/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2215 - Find the Difference of Two Arrays</title>
    <link href="http://oj.roy4801.tw/2023/05/03/leetcode/2215/"/>
    <id>http://oj.roy4801.tw/2023/05/03/leetcode/2215/</id>
    <published>2023-05-03T20:30:30.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-the-difference-of-two-arrays/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個 array &lt;code&gt;nums1&lt;/code&gt;, &lt;code&gt;nums2&lt;/code&gt;，要你回傳長度 2 的 &lt;code&gt;vector&amp;lt;vector&amp;lt;int&amp;gt;&amp;gt;&lt;/code&gt; 答案陣列&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ans[0]&lt;/code&gt; 是 &lt;code&gt;nums1&lt;/code&gt; 中&lt;strong&gt;不重複&lt;/strong&gt;且沒出現在 &lt;code&gt;nums2&lt;/code&gt; 中的數字&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ans[1]&lt;/code&gt; 是 &lt;code&gt;nums2&lt;/code&gt; 中&lt;strong&gt;不重複&lt;/strong&gt;且沒出現在 &lt;code&gt;nums1&lt;/code&gt; 中的數字&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;測資限制：&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1523 - Count Odd Numbers in an Interval Range</title>
    <link href="http://oj.roy4801.tw/2023/03/13/leetcode/1523/"/>
    <id>http://oj.roy4801.tw/2023/03/13/leetcode/1523/</id>
    <published>2023-03-13T23:23:04.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-odd-numbers-in-an-interval-range&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個非負整數 &lt;code&gt;low&lt;/code&gt;, &lt;code&gt;high&lt;/code&gt; 問你介於兩者之間的奇數有多少個(包含)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制: $0 &#92;le low &#92;le high &#92;le 10^9$&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="math" scheme="http://oj.roy4801.tw/tags/math/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="interval" scheme="http://oj.roy4801.tw/tags/interval/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 50 - Pow(x, n)</title>
    <link href="http://oj.roy4801.tw/2023/02/20/leetcode/50/"/>
    <id>http://oj.roy4801.tw/2023/02/20/leetcode/50/</id>
    <published>2023-02-20T00:29:45.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/powx-n/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;實作 &lt;code&gt;pow(x, n)&lt;/code&gt; 意即 $x^n$&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$-100.0 &amp;lt; x &amp;lt; 100.0$&lt;/li&gt;
&lt;li&gt;$-2^{31} &#92;le n &#92;le 2^{31}-1$&lt;/li&gt;
&lt;li&gt;$-10^4 &#92;le x^n &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 103 - Binary Tree Zigzag Level Order Traversal</title>
    <link href="http://oj.roy4801.tw/2023/02/19/leetcode/103/"/>
    <id>http://oj.roy4801.tw/2023/02/19/leetcode/103/</id>
    <published>2023-02-19T23:35:48.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/02/19/tree1.jpg&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一顆二元樹 &lt;code&gt;root&lt;/code&gt;，問你回傳 zigzag 的順序&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$0 &#92;le N &#92;le 2000$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1470 - Shuffle the Array</title>
    <link href="http://oj.roy4801.tw/2023/02/06/leetcode/1470/"/>
    <id>http://oj.roy4801.tw/2023/02/06/leetcode/1470/</id>
    <published>2023-02-06T20:58:33.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/shuffle-the-array/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;nums&lt;/code&gt; 有 &lt;code&gt;2n&lt;/code&gt; 個元素 &lt;code&gt;[x1, x2, ..., xn, y1, y2, ..., yn]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;要你回傳 &lt;code&gt;[x1, y1, x2, y2, ..., xn, yn]&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 500$&lt;/li&gt;
&lt;li&gt;$1 &#92;le nums[i] &#92;le 10^3$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 438 - Find All Anagrams in a String</title>
    <link href="http://oj.roy4801.tw/2023/02/05/leetcode/438/"/>
    <id>http://oj.roy4801.tw/2023/02/05/leetcode/438/</id>
    <published>2023-02-05T20:40:30.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-all-anagrams-in-a-string/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s1&lt;/code&gt; 和 &lt;code&gt;s2&lt;/code&gt;，問你 &lt;code&gt;s1&lt;/code&gt; 的排列組合是不是 &lt;code&gt;s2&lt;/code&gt; 的子字串，回傳所有的 index&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;s = &amp;quot;cbaebabacd&amp;quot;, p = &amp;quot;abc&amp;quot;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;// output [0, 6]&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le len &#92;le 3&#92;cdot10^4$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
    <category term="sliding window" scheme="http://oj.roy4801.tw/tags/sliding-window/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 567 - Permutation in String</title>
    <link href="http://oj.roy4801.tw/2023/02/05/leetcode/567/"/>
    <id>http://oj.roy4801.tw/2023/02/05/leetcode/567/</id>
    <published>2023-02-05T00:11:58.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/permutation-in-string/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s1&lt;/code&gt; 和 &lt;code&gt;s2&lt;/code&gt;，問你 &lt;code&gt;s1&lt;/code&gt; 的排列組合是不是 &lt;code&gt;s2&lt;/code&gt; 的子字串&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le len &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
    <category term="sliding window" scheme="http://oj.roy4801.tw/tags/sliding-window/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 787 - Cheapest Flights Within K Stops</title>
    <link href="http://oj.roy4801.tw/2023/01/26/leetcode/787/"/>
    <id>http://oj.roy4801.tw/2023/01/26/leetcode/787/</id>
    <published>2023-01-26T18:43:58.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/cheapest-flights-within-k-stops/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2022/03/18/cheapest-flights-within-k-stops-3drawio.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;有 $n$ 座城市由 &lt;code&gt;flights[i] = [fromi, toi, pricei]&lt;/code&gt; 個班機來往，給你起始點&lt;code&gt;src&lt;/code&gt;和結束點&lt;code&gt;dst&lt;/code&gt;以及整數 &lt;code&gt;k&lt;/code&gt; (代表最多停留 &lt;code&gt;k&lt;/code&gt; 個城市)，問你最便宜要花多少錢，如果沒有這種路徑則回傳 &lt;code&gt;-1&lt;/code&gt;。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;$0 &#92;le flights.length &#92;le (n * (n - 1) / 2)$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="dijkstra" scheme="http://oj.roy4801.tw/tags/dijkstra/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2359 - Find Closest Node to Given Two Nodes</title>
    <link href="http://oj.roy4801.tw/2023/01/25/leetcode/2359/"/>
    <id>http://oj.roy4801.tw/2023/01/25/leetcode/2359/</id>
    <published>2023-01-25T22:53:04.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-closest-node-to-given-two-nodes/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2022/06/07/graph4drawio-2.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個有 $n$ 個點的&lt;strong&gt;有向圖&lt;/strong&gt;，每個點只有一條邊，並且給你兩個整數 &lt;code&gt;node1&lt;/code&gt; 和 &lt;code&gt;node2&lt;/code&gt;，要你回傳一個 &lt;code&gt;node i&lt;/code&gt; (&lt;code&gt;node1&lt;/code&gt; 和 &lt;code&gt;node2&lt;/code&gt; 都到得了) ，其 index 使得 “&lt;code&gt;node1&lt;/code&gt; 到 &lt;code&gt;node i&lt;/code&gt; 的距離” 和 “&lt;code&gt;node2&lt;/code&gt; 到 &lt;code&gt;node i&lt;/code&gt; 的距離” 的最大值越小越好&lt;br&gt;
如果有多種解，回傳 index 最小的即可；無解回傳 &lt;code&gt;-1&lt;/code&gt;。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$2 &#92;le n &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;&lt;code&gt;edge.size() = n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;可能有出現環，但一定沒有自環&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 491 - Non-decreasing Subsequences</title>
    <link href="http://oj.roy4801.tw/2023/01/21/leetcode/491/"/>
    <id>http://oj.roy4801.tw/2023/01/21/leetcode/491/</id>
    <published>2023-01-21T03:02:53.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/non-decreasing-subsequences/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 &lt;code&gt;nums&lt;/code&gt; 要你回傳所有大於兩個元素的&lt;strong&gt;非遞減子序列&lt;/strong&gt;，回傳不用管順序。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資限制:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le nums.size() &#92;le 15$&lt;/li&gt;
&lt;li&gt;$-100 &#92;le nums[i] &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 57 - Insert Interval</title>
    <link href="http://oj.roy4801.tw/2023/01/17/leetcode/57/"/>
    <id>http://oj.roy4801.tw/2023/01/17/leetcode/57/</id>
    <published>2023-01-17T00:11:04.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/insert-interval/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一堆不重疊的區間 &lt;code&gt;intervals[i] = (s_i, e_i)&lt;/code&gt;，今天有個新的區間 &lt;code&gt;newInterval&lt;/code&gt;，如果有重疊，則只留下最大區間，問你最後的區間 array 長怎樣&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;輸入
&lt;ul&gt;
&lt;li&gt;$N &#92;le 10^4$ (&lt;code&gt;intervals.size()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;$0 &#92;le s_i &#92;le e_i &#92;le 10^5$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="interval" scheme="http://oj.roy4801.tw/tags/interval/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1061 - Lexicographically Smallest Equivalent String</title>
    <link href="http://oj.roy4801.tw/2023/01/15/leetcode/1061/"/>
    <id>http://oj.roy4801.tw/2023/01/15/leetcode/1061/</id>
    <published>2023-01-15T22:47:35.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/lexicographically-smallest-equivalent-string/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s1&lt;/code&gt; 和 &lt;code&gt;s2&lt;/code&gt; 還有一個 &lt;code&gt;baseStr&lt;/code&gt;，其中 &lt;code&gt;s1[i]&lt;/code&gt; 和 &lt;code&gt;s2[i]&lt;/code&gt; 是 equivalent characters，今天給你 &lt;code&gt;baseStr&lt;/code&gt; 問你如果用 equivalence relation 替換掉字母後，字典序最小的字串為何?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Equivalence relation:
&lt;ul&gt;
&lt;li&gt;Reflexivity: &lt;code&gt;&#39;a&#39; == &#39;a&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Symmetry: &lt;code&gt;&#39;a&#39; == &#39;b&#39;&lt;/code&gt; $&#92;rightarrow$ &lt;code&gt;&#39;b&#39; == &#39;a&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Transitivity: &lt;code&gt;&#39;a&#39; == &#39;b&#39;&lt;/code&gt;, &lt;code&gt;&#39;b&#39; == &#39;c&#39;&lt;/code&gt; 代表 &lt;code&gt;&#39;a&#39; == &#39;c&#39;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="disjoint set" scheme="http://oj.roy4801.tw/tags/disjoint-set/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 144 - Binary Tree Preorder Traversal</title>
    <link href="http://oj.roy4801.tw/2023/01/09/leetcode/144/"/>
    <id>http://oj.roy4801.tw/2023/01/09/leetcode/144/</id>
    <published>2023-01-09T22:31:48.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/binary-tree-preorder-traversal/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;Binary Tree Traversal (pre-order)&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;DFS&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 134 - Gas Station</title>
    <link href="http://oj.roy4801.tw/2023/01/08/leetcode/134/"/>
    <id>http://oj.roy4801.tw/2023/01/08/leetcode/134/</id>
    <published>2023-01-08T04:24:02.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/gas-station/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 &lt;code&gt;n&lt;/code&gt; 個排成圓形的加油站，每個加油站有 &lt;code&gt;gas[i]&lt;/code&gt; 的油，從第 &lt;code&gt;i&lt;/code&gt; 個加油站到第 &lt;code&gt;i+1&lt;/code&gt; 個加油站要花 &lt;code&gt;cost[i]&lt;/code&gt; 的油&lt;br&gt;
問你如果順時針走完所有的加油站，要從哪個加油站出發? (從 &lt;code&gt;0&lt;/code&gt; 開始)，如果不能走完回傳 &lt;code&gt;-1&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;貪心，從第 0 個加油站開始走，如果當前油量小於 0 ，就 reset 從下個加油站開始走，直到路徑總共走完 &lt;code&gt;n&lt;/code&gt; 個加油站&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1833 - Maximum Ice Cream Bars</title>
    <link href="http://oj.roy4801.tw/2023/01/06/leetcode/1833/"/>
    <id>http://oj.roy4801.tw/2023/01/06/leetcode/1833/</id>
    <published>2023-01-06T21:42:43.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-ice-cream-bars/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;n&lt;/code&gt; 個冰淇淋價格是 &lt;code&gt;cost[i]&lt;/code&gt; 今天你有 &lt;code&gt;coins&lt;/code&gt; 元，問你最多可以買幾個?&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;sort 從最小的開始挑&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2244 - Minimum Rounds to Complete All Tasks</title>
    <link href="http://oj.roy4801.tw/2023/01/04/leetcode/2244/"/>
    <id>http://oj.roy4801.tw/2023/01/04/leetcode/2244/</id>
    <published>2023-01-04T22:58:16.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-rounds-to-complete-all-tasks/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;N&lt;/code&gt; 其中 &lt;code&gt;N[i]&lt;/code&gt; 代表工作的困難度，每回合可以完成兩個或三個同等級的工作，問你最少要幾回合?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;測資範圍:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le N.size() &#92;le 10^5$&lt;/li&gt;
&lt;li&gt;$1 &#92;le N[i] &#92;le 10^9$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 944 - Delete Columns to Make Sorted</title>
    <link href="http://oj.roy4801.tw/2023/01/03/leetcode/944/"/>
    <id>http://oj.roy4801.tw/2023/01/03/leetcode/944/</id>
    <published>2023-01-03T23:40:14.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/delete-columns-to-make-sorted/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;n&lt;/code&gt; 個字串 e.g. &lt;code&gt;&amp;#123;&amp;quot;abc&amp;quot;, &amp;quot;bce&amp;quot;, &amp;quot;cae&amp;quot;&amp;#125;&lt;/code&gt;，把字串排成一直排，問你每一行是不是字典序排好的，如果不是則刪掉那一個直排，最多能刪掉多少行?&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;a b c&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;b c e&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;c a e&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;v x v = 1&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;測資範圍:
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 100$&lt;/li&gt;
&lt;li&gt;$1 &#92;le str.size() &#92;le 1000$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 290 - Word Pattern</title>
    <link href="http://oj.roy4801.tw/2023/01/02/leetcode/290/"/>
    <id>http://oj.roy4801.tw/2023/01/02/leetcode/290/</id>
    <published>2023-01-02T19:03:58.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/word-pattern/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;pattern&lt;/code&gt; 和字串 &lt;code&gt;s&lt;/code&gt; 問你 &lt;code&gt;pattern&lt;/code&gt; 和 &lt;code&gt;s&lt;/code&gt; 是不是 full match&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;&amp;quot;abba&amp;quot; -&amp;gt; &amp;quot;dog cat cat dog&amp;quot;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= pattern.length &amp;lt;= 300&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= s.length &amp;lt;= 3000&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 520 - Detect Capital</title>
    <link href="http://oj.roy4801.tw/2023/01/02/leetcode/520/"/>
    <id>http://oj.roy4801.tw/2023/01/02/leetcode/520/</id>
    <published>2023-01-02T17:21:52.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/detect-capital/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個字串 &lt;code&gt;s&lt;/code&gt; 問你能不能判斷它是不是: 全大寫、第一個字大寫其他小寫、全小寫。如果一個字串是以上三種情況，則返回 &lt;code&gt;true&lt;/code&gt; ；否則，返回 &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;寫個狀態機判斷&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 797 - All Paths From Source to Target</title>
    <link href="http://oj.roy4801.tw/2022/12/30/leetcode/797/"/>
    <id>http://oj.roy4801.tw/2022/12/30/leetcode/797/</id>
    <published>2022-12-30T23:44:39.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/all-paths-from-source-to-target/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2020/09/28/all_1.jpg&quot; alt=&quot;graph&quot;&gt;&lt;/p&gt;
&lt;p&gt;給你一個 &lt;code&gt;n&lt;/code&gt; 個點的有向無環圖(DAG)，問你可不可以找到所有從 &lt;code&gt;0&lt;/code&gt; 到 &lt;code&gt;n-1&lt;/code&gt; 的路徑。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1962 - Remove Stones to Minimize the Total</title>
    <link href="http://oj.roy4801.tw/2022/12/28/leetcode/1962/"/>
    <id>http://oj.roy4801.tw/2022/12/28/leetcode/1962/</id>
    <published>2022-12-28T22:28:10.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/remove-stones-to-minimize-the-total/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;N[i]&lt;/code&gt; 代表石頭的個數，再給你一個數字 &lt;code&gt;k&lt;/code&gt; 代表操作數，操作方法如下:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;選一堆石頭 &lt;code&gt;N[i]&lt;/code&gt; 然後從裡面拿走 &lt;code&gt;floor(N[i]/2.0)&lt;/code&gt;&lt;br&gt;
問你最後拿完石頭的總和&lt;strong&gt;最小&lt;/strong&gt;為多少?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;$1 &#92;le N.size() &#92;le 10^5$&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;$1 &#92;le N[i] &#92;le 10^4$&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;$1 &#92;le k &#92;le 10^5$&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2279 - Maximum Bags With Full Capacity of Rocks1</title>
    <link href="http://oj.roy4801.tw/2022/12/27/leetcode/2279/"/>
    <id>http://oj.roy4801.tw/2022/12/27/leetcode/2279/</id>
    <published>2022-12-27T23:05:40.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-bags-with-full-capacity-of-rocks/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 &lt;code&gt;n&lt;/code&gt; 個包包，每個包包的容量是 &lt;code&gt;A[i]&lt;/code&gt; 裡面已經裝了 &lt;code&gt;B[i]&lt;/code&gt; 個石頭，你身上有 &lt;code&gt;m&lt;/code&gt; 顆石頭，問你最多可以放滿幾個包包&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;貪心&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 55 - Jump Game</title>
    <link href="http://oj.roy4801.tw/2022/12/26/leetcode/55/"/>
    <id>http://oj.roy4801.tw/2022/12/26/leetcode/55/</id>
    <published>2022-12-26T22:52:56.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/jump-game/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 其中 &lt;code&gt;nums[i]&lt;/code&gt; 代表最大可以往右跳的距離，問你是否跳得到最後一格&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le N &#92;le 10^4$&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 886 - Possible Bipartition</title>
    <link href="http://oj.roy4801.tw/2022/12/25/leetcode/886/"/>
    <id>http://oj.roy4801.tw/2022/12/25/leetcode/886/</id>
    <published>2022-12-25T23:22:36.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/possible-bipartition/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 &lt;code&gt;n&lt;/code&gt; 個人(&lt;code&gt;1&lt;/code&gt;…&lt;code&gt;n&lt;/code&gt;)，和 &lt;code&gt;dislike&lt;/code&gt; 陣列其中 &lt;code&gt;dislike[i] = (a_i, b_i)&lt;/code&gt; 代表 &lt;code&gt;a&lt;/code&gt; 不喜歡 &lt;code&gt;b&lt;/code&gt;。&lt;br&gt;
問你能不能把這群人分成兩組，組內的人不能互相不喜歡。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;這題是判斷是不是二分圖裸題，確認圖上是否有奇環，或是可以想成著色問題，相鄰的兩個點不同色&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="二分圖" scheme="http://oj.roy4801.tw/tags/%E4%BA%8C%E5%88%86%E5%9C%96/"/>
    
    <category term="著色問題" scheme="http://oj.roy4801.tw/tags/%E8%91%97%E8%89%B2%E5%95%8F%E9%A1%8C/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2389 - Longest Subsequence With Limited Sum</title>
    <link href="http://oj.roy4801.tw/2022/12/25/leetcode/2389/"/>
    <id>http://oj.roy4801.tw/2022/12/25/leetcode/2389/</id>
    <published>2022-12-25T23:12:04.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/longest-subsequence-with-limited-sum/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 長度 &lt;code&gt;n&lt;/code&gt;，接著長度 &lt;code&gt;m&lt;/code&gt; 的陣列 &lt;code&gt;queries&lt;/code&gt; 代表詢問&lt;br&gt;
問你能不能回答一個長度 &lt;code&gt;m&lt;/code&gt; 的陣列 &lt;code&gt;answer&lt;/code&gt;，&lt;code&gt;answer[i]&lt;/code&gt; 代表 &lt;code&gt;nums&lt;/code&gt; 中的數字加起來 $&#92;le$ &lt;code&gt;queries[i]&lt;/code&gt; 最大的長度&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目沒有問 subsequence 的內容，只問長度，所以可以 sort &lt;code&gt;nums&lt;/code&gt;，然後從小的加到大的，當 sum 大於 &lt;code&gt;queries[i]&lt;/code&gt; 時紀錄長度即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1971 - Find if Path Exists in Graph</title>
    <link href="http://oj.roy4801.tw/2022/12/19/leetcode/1971/"/>
    <id>http://oj.roy4801.tw/2022/12/19/leetcode/1971/</id>
    <published>2022-12-19T23:07:19.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-if-path-exists-in-graph/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個雙向圖有 $n$ 個點 $m$ 條邊，從 $0$ 到 $n-1$，問你能不能從 &lt;code&gt;src&lt;/code&gt; 走到 &lt;code&gt;dst&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le n &#92;le 2e5$&lt;/li&gt;
&lt;li&gt;$0 &#92;le m &#92;le 2e5$&lt;/li&gt;
&lt;li&gt;沒有重複的邊 or 自環&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="disjoint set" scheme="http://oj.roy4801.tw/tags/disjoint-set/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 150 - Evaluate Reverse Polish Notation</title>
    <link href="http://oj.roy4801.tw/2022/12/19/leetcode/150/"/>
    <id>http://oj.roy4801.tw/2022/12/19/leetcode/150/</id>
    <published>2022-12-19T00:20:32.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/evaluate-reverse-polish-notation/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個&lt;a href=&quot;https://zh.wikipedia.org/wiki/%E9%80%86%E6%B3%A2%E5%85%B0%E8%A1%A8%E7%A4%BA%E6%B3%95&quot;&gt;逆波蘭表達式(Reverse Polish notation)&lt;/a&gt; 要你求值&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;用一個 stack 即可，遇到數字 push 到 stack 中，遇到 op 則 pop 兩個數字然後計算後再 push 回去&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="stack" scheme="http://oj.roy4801.tw/tags/stack/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 739 - Daily Temperatures</title>
    <link href="http://oj.roy4801.tw/2022/12/18/leetcode/739/"/>
    <id>http://oj.roy4801.tw/2022/12/18/leetcode/739/</id>
    <published>2022-12-18T22:52:40.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/daily-temperatures/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 $T[i]$ 要你回答一個整數陣列 $ans$ ，其中 $ans[i]$ 代表對於第 $i$ 天的溫度 $T[i]$ 會存在一個溫度 $T[j]$ 且 $j = i + ans[i]$ 使得 $T[i] &amp;lt; T[j]$&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;naive: 對每個數字往後去找第一個比它大的 $O(n^2)$ TLE&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="monotonic stack" scheme="http://oj.roy4801.tw/tags/monotonic-stack/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1143 - Longest Common Subsequence Medium</title>
    <link href="http://oj.roy4801.tw/2022/12/15/leetcode/1143/"/>
    <id>http://oj.roy4801.tw/2022/12/15/leetcode/1143/</id>
    <published>2022-12-15T21:11:27.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/longest-common-subsequence/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s1&lt;/code&gt; 和 &lt;code&gt;s2&lt;/code&gt; 問你最常共同子序列(LCS)長度多少?&lt;/p&gt;
&lt;p&gt;&lt;code&gt;1 &amp;lt;= s1.size(), s2.size() &amp;lt;= 1000&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="LCS" scheme="http://oj.roy4801.tw/tags/LCS/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 198 - House Robber</title>
    <link href="http://oj.roy4801.tw/2022/12/14/leetcode/198/"/>
    <id>http://oj.roy4801.tw/2022/12/14/leetcode/198/</id>
    <published>2022-12-14T22:07:20.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/house-robber/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數陣列 &lt;code&gt;M[i]&lt;/code&gt; 代表 第 $i$ 間房子的價值，你今天是小偷要去偷錢，但是有個限制是不能連續偷(偷第 $i$ 間，第 $i-1$ 和 $i+1$ 都不能偷)，否則會被抓到，問你最大能偷多少?&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;對於 $1$ 到 $i$ 能偷的總價值，假如你挑了第 $i$ 間房子，那一定是和第 $i-2$ 間的房子加總起來($W[i]+W[i-2]$)；如果不挑 $i$ 那必定是 $i-1$ ($W[i-1]$)，而要求兩者最大，所以取 max&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 931 - Minimum Falling Path Sum</title>
    <link href="http://oj.roy4801.tw/2022/12/14/leetcode/931/"/>
    <id>http://oj.roy4801.tw/2022/12/14/leetcode/931/</id>
    <published>2022-12-14T01:09:59.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-falling-path-sum/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://assets.leetcode.com/uploads/2021/11/03/failing1-grid.jpg&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給你一個 &lt;code&gt;nxn&lt;/code&gt; 的陣列，問你從上面走到最下面&lt;strong&gt;最短路徑總和&lt;/strong&gt;為多少?&lt;br&gt;
可以左右斜著走，但只能往下走，意即對於位置 $(i, j)$ 可以往 $(i+1, j-1)$ (左下),  $(i+1, j)$ (下方),  $(i+1, j-1)$ (右下) 走&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 70 - Climbing Stairs</title>
    <link href="http://oj.roy4801.tw/2022/12/12/leetcode/70/"/>
    <id>http://oj.roy4801.tw/2022/12/12/leetcode/70/</id>
    <published>2022-12-12T22:31:20.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/climbing-stairs/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一個 &lt;code&gt;n&lt;/code&gt; 階的樓梯，每次可以走 &lt;code&gt;1&lt;/code&gt; 階或 &lt;code&gt;2&lt;/code&gt; 階，問你有幾種不同的走法&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;當前的走法 $i$ 可以是 $i-1$ 走 1 或是 $i-2$ 走 2 的總和，總共 0 階和 1 階的方法數是 1&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 938 - Range Sum of BST</title>
    <link href="http://oj.roy4801.tw/2022/12/07/leetcode/938/"/>
    <id>http://oj.roy4801.tw/2022/12/07/leetcode/938/</id>
    <published>2022-12-07T21:50:30.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/range-sum-of-bst/description/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個二元搜尋樹，問你加總數值在 &lt;code&gt;[low, high]&lt;/code&gt; 之間的 node&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;DFS 加總即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 876 - Middle of the Linked List</title>
    <link href="http://oj.roy4801.tw/2022/12/05/leetcode/876/"/>
    <id>http://oj.roy4801.tw/2022/12/05/leetcode/876/</id>
    <published>2022-12-05T21:58:54.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/middle-of-the-linked-list/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個 linked-list 問你能不能回傳中間的 node，如果有兩個中間的，則回傳後者。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;le N[i] &#92;le 100$&lt;/li&gt;
&lt;li&gt;$1 &#92;le N.size() &#92;le 100$&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1207 - Unique Number of Occurrences</title>
    <link href="http://oj.roy4801.tw/2022/11/30/leetcode/1207/"/>
    <id>http://oj.roy4801.tw/2022/11/30/leetcode/1207/</id>
    <published>2022-11-30T23:09:36.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/unique-number-of-occurrences/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;n&lt;/code&gt; 其中 &lt;code&gt;1 &amp;lt;= n.size() &amp;lt;= 1000&lt;/code&gt; 且 &lt;code&gt;-1000 &amp;lt;= n[i] &amp;lt;= 1000&lt;/code&gt; 問你陣列數字&lt;strong&gt;出現的次數&lt;/strong&gt;有沒有重複，沒有重複輸出 &lt;code&gt;true&lt;/code&gt; 反之輸出 &lt;code&gt;false&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;e.g. &lt;code&gt;[1,2,2,1,1,3] = true&lt;/code&gt; =&amp;gt; 1 出現 3 次，2 出現 2 次，3 出現 1 次，出現的次數都不重複&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 242 - Valid Anagram</title>
    <link href="http://oj.roy4801.tw/2022/07/26/leetcode/242/"/>
    <id>http://oj.roy4801.tw/2022/07/26/leetcode/242/</id>
    <published>2022-07-26T00:54:01.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/valid-anagram/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你兩個字串 &lt;code&gt;s&lt;/code&gt; 和 &lt;code&gt;t&lt;/code&gt; 問你 &lt;code&gt;s&lt;/code&gt; 重新排順序能不能變成 &lt;code&gt;t&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;紀錄兩個字串每個字母出現的頻率，接著比較頻率表即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 36 - Valid Sudoku</title>
    <link href="http://oj.roy4801.tw/2022/07/20/leetcode/36/"/>
    <id>http://oj.roy4801.tw/2022/07/20/leetcode/36/</id>
    <published>2022-07-20T23:59:34.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/valid-sudoku/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給一個 &lt;code&gt;9x9&lt;/code&gt; 數獨，問你是不是合法的&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照著規則實作&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2221 - Find Triangular Sum of an Array</title>
    <link href="http://oj.roy4801.tw/2022/07/20/leetcode/2221/"/>
    <id>http://oj.roy4801.tw/2022/07/20/leetcode/2221/</id>
    <published>2022-07-20T23:34:44.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-triangular-sum-of-an-array/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/r7HM3Zc.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;給一個陣列 &lt;code&gt;nums&lt;/code&gt; 相鄰的兩個元素加起來 $% 10$ 成為新的元素，問最後剩下的一個元素值為何&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 119 - Pascal&#39;s Triangle II</title>
    <link href="http://oj.roy4801.tw/2022/07/20/leetcode/119/"/>
    <id>http://oj.roy4801.tw/2022/07/20/leetcode/119/</id>
    <published>2022-07-20T20:01:53.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/pascals-triangle-ii/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;r&lt;/code&gt; 要你求第 &lt;code&gt;r&lt;/code&gt; 層的帕斯卡三角形&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照著帕斯卡三角形的規則建立即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 118 - Pascal&#39;s Triangle</title>
    <link href="http://oj.roy4801.tw/2022/07/20/leetcode/118/"/>
    <id>http://oj.roy4801.tw/2022/07/20/leetcode/118/</id>
    <published>2022-07-20T19:52:45.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/pascals-triangle/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你 &lt;code&gt;n&lt;/code&gt; 要你建 &lt;code&gt;n&lt;/code&gt; 層的帕斯卡三角形&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照著帕斯卡三角形的規則建立即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 566 - Reshape the Matrix</title>
    <link href="http://oj.roy4801.tw/2022/07/19/leetcode/566/"/>
    <id>http://oj.roy4801.tw/2022/07/19/leetcode/566/</id>
    <published>2022-07-19T00:21:20.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/reshape-the-matrix/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;把 &lt;code&gt;mxn&lt;/code&gt; 的 matrix 轉成 &lt;code&gt;rxc&lt;/code&gt; 的 matrix&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照著實作即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 217 - Contains Duplicate</title>
    <link href="http://oj.roy4801.tw/2022/07/14/leetcode/217/"/>
    <id>http://oj.roy4801.tw/2022/07/14/leetcode/217/</id>
    <published>2022-07-14T16:48:04.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/contains-duplicate/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個陣列 &lt;code&gt;n&lt;/code&gt; 問你有沒有重複的元素，有的話輸出 true，反之 false。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;直覺 sort 後判斷前後有沒有一樣即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 557 - Reverse Words in a String III</title>
    <link href="http://oj.roy4801.tw/2022/03/26/leetcode/557/"/>
    <id>http://oj.roy4801.tw/2022/03/26/leetcode/557/</id>
    <published>2022-03-26T23:55:02.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/reverse-words-in-a-string-iii/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給定一個字串，要你把所有 word (空白隔開) 反轉&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;從左往右掃，遇到空白就把前面的頭尾反轉&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 344 - Reverse String</title>
    <link href="http://oj.roy4801.tw/2022/03/26/leetcode/344/"/>
    <id>http://oj.roy4801.tw/2022/03/26/leetcode/344/</id>
    <published>2022-03-26T23:51:29.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/reverse-string/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;反轉一個字串&lt;/p&gt;
&lt;p&gt;follow-up: in-place 且 $O(1)$&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 991 - Broken Calculator</title>
    <link href="http://oj.roy4801.tw/2022/03/26/leetcode/991/"/>
    <id>http://oj.roy4801.tw/2022/03/26/leetcode/991/</id>
    <published>2022-03-26T23:20:26.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/broken-calculator/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一個壞掉的計算機，只能做兩種操作:乘二、減一。給你 &lt;code&gt;startValue&lt;/code&gt; 和 &lt;code&gt;target&lt;/code&gt; 問你最少幾步驟可以將 &lt;code&gt;startValue&lt;/code&gt; 轉成 &lt;code&gt;target&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;TODO&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1029 - Two City Scheduling</title>
    <link href="http://oj.roy4801.tw/2022/03/26/leetcode/1029/"/>
    <id>http://oj.roy4801.tw/2022/03/26/leetcode/1029/</id>
    <published>2022-03-26T00:33:12.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/two-city-scheduling/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 2n 組數對 &lt;code&gt;[a_i, b_i]&lt;/code&gt; 今天挑 $n$ 個 $a_i$ 相加，剩下的 $n$ 的 $b_i$ 相加，問你出來值最小多少?&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;直覺想法 按照大小 sort 接著從小的開始挑，但是 $b$ 就不保證是小的，有個想法是把每組 $(a_i, b_i)$ 變成 $x_i = a_i - b_i$，如果 $x$ 比較小，代表該數對的 $a$ 較大；如果 $x$ 比較大，代表該數對的 $b$ 較大。&lt;br&gt;
按照 $a_i - b_i$ sort 之後，從小的開始挑 $n$ 個 + a，接著再挑 $n$ 個 + b 即可。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 881 - Boats to Save People</title>
    <link href="http://oj.roy4801.tw/2022/03/24/leetcode/881/"/>
    <id>http://oj.roy4801.tw/2022/03/24/leetcode/881/</id>
    <published>2022-03-24T11:33:08.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/boats-to-save-people/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個整數陣列 &lt;code&gt;people[i]&lt;/code&gt; 是每個人的重量，今天要搭船過河，每條船最多載重 &lt;code&gt;limit&lt;/code&gt;，一艘船最多載兩個人，問你最少需要幾條船。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= people.length &amp;lt;= 5 * 10^4&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= people[i] &amp;lt;= limit &amp;lt;= 3 * 10^4&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 763 - Partition Labels</title>
    <link href="http://oj.roy4801.tw/2022/03/24/leetcode/763/"/>
    <id>http://oj.roy4801.tw/2022/03/24/leetcode/763/</id>
    <published>2022-03-24T00:07:43.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/partition-labels/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給定一個字串，問你如果把字串分組，靠得近的分在同一組，組數越少越好，要你回傳分組狀態&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;ababcbacadefegdehijhklij =&amp;gt; [9, 7, 8]&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;ababcbaca | defegde | hijhklij&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;^abc        ^defg     ^hijkl&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 167 - Two Sum II - Input Array Is Sorted</title>
    <link href="http://oj.roy4801.tw/2022/03/22/leetcode/167/"/>
    <id>http://oj.roy4801.tw/2022/03/22/leetcode/167/</id>
    <published>2022-03-22T13:53:07.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個 1-index 的整數陣列(已排序)，問你陣列裡加起來等於 &lt;code&gt;target&lt;/code&gt; 的兩個數字 index 為何&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;naive $&#92;mathcal{O}(n^2)$ 作法會超時&lt;br&gt;
掃一次，對於 index &lt;code&gt;i&lt;/code&gt; 每次去數字的右邊($[i+1, n)$)找是否有 &lt;code&gt;t - n[i]&lt;/code&gt; 的數字存在，二分搜加速&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1663 - Smallest String With A Given Numeric Value</title>
    <link href="http://oj.roy4801.tw/2022/03/22/leetcode/1663/"/>
    <id>http://oj.roy4801.tw/2022/03/22/leetcode/1663/</id>
    <published>2022-03-22T10:59:20.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/smallest-string-with-a-given-numeric-value/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你兩個數字 &lt;code&gt;n&lt;/code&gt; 和 &lt;code&gt;k&lt;/code&gt; 問你: 由 &lt;code&gt;n&lt;/code&gt; 個字母組成，所有字母加起來總和為 &lt;code&gt;k&lt;/code&gt; 且字串&lt;strong&gt;字典序最小&lt;/strong&gt;。&lt;br&gt;
a=1, b=2, …, z=26&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;最優的答案是後面都是 &lt;code&gt;z&lt;/code&gt; 前面都是 &lt;code&gt;a&lt;/code&gt;，先貪心找最後的 &lt;code&gt;z&lt;/code&gt; 長度: 對於字串 &lt;code&gt;Z = aa...z = 1*(a長度) + 26&lt;/code&gt; 假如 k 大於 &lt;code&gt;Z&lt;/code&gt; 的話，則最後一定可以擺一個 &lt;code&gt;z&lt;/code&gt;，亦即 &lt;code&gt;k &amp;gt;= 1*(n-1) + 26&lt;/code&gt;。&lt;br&gt;
接下來就都擺 &lt;code&gt;a&lt;/code&gt; ，中間的字母(夾在 &lt;code&gt;a&lt;/code&gt; 和 &lt;code&gt;z&lt;/code&gt; 中間 e.g. “aa…x…zz”)，就擺 &lt;code&gt;&#39;a&#39;+(k-1)&lt;/code&gt;&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2212 - Maximum Points in an Archery Competition</title>
    <link href="http://oj.roy4801.tw/2022/03/21/leetcode/2212/"/>
    <id>http://oj.roy4801.tw/2022/03/21/leetcode/2212/</id>
    <published>2022-03-21T16:34:59.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-points-in-an-archery-competition/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 Alice 和 Bob 比賽射箭，每個人有 &lt;code&gt;numArrows&lt;/code&gt; 支箭 ，一人各射 12 局，規則是: 如果第 $i$ 局的分數比另一個人大，$A_i &#92;ge B_i$ 則 A 得到 $i$ 分。&lt;br&gt;
今天 Alice 先射完了，他的結果是 &lt;code&gt;[aliceArrows_0, aliceArrows_11]&lt;/code&gt; ，問你 Bob 的結果長怎樣，他的得分才會是最大的&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;這題有兩種做法: 爆搜和 DP。&lt;br&gt;
之所以可以爆搜是因為局數 只有 12 局，所以能在 $&#92;mathcal{O}(2^12)$ 內做完，bitwise 枚舉也是一樣。DP 則是把箭數當重量、得分當價值的話，問題就變成了 0/1 背包 $&#92;mathcal{O}(nm), n=&#92;text{12}, m=10^5$&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
    <category term="bitwise 枚舉" scheme="http://oj.roy4801.tw/tags/bitwise-%E6%9E%9A%E8%88%89/"/>
    
    <category term="背包" scheme="http://oj.roy4801.tw/tags/%E8%83%8C%E5%8C%85/"/>
    
    <category term="暴搜" scheme="http://oj.roy4801.tw/tags/%E6%9A%B4%E6%90%9C/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2211 - Count Collisions on a Road</title>
    <link href="http://oj.roy4801.tw/2022/03/21/leetcode/2211/"/>
    <id>http://oj.roy4801.tw/2022/03/21/leetcode/2211/</id>
    <published>2022-03-21T09:57:53.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-collisions-on-a-road/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;一條路上有 $n$ 台車，每台車可以有三種方向: &lt;code&gt;S&lt;/code&gt;, &lt;code&gt;L&lt;/code&gt;, &lt;code&gt;R&lt;/code&gt; 分別是靜止、左、右。今天每台車都朝其方向駛去，當相撞時車子留在原地，問你給定一個 &lt;code&gt;directions&lt;/code&gt; 序列，有幾台車會撞車。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;可以觀察到 &lt;code&gt;RS&lt;/code&gt;, &lt;code&gt;SL&lt;/code&gt;, &lt;code&gt;RL&lt;/code&gt; 這三種狀況一定會撞到，但如果序列是 &lt;code&gt;RRL&lt;/code&gt; 則最一開始的 R 不會算到，所以必須要記錄 &lt;code&gt;R&lt;/code&gt; 的數量，當遇到前面三種撞車的狀況時，就將目前算到 `R 的數量也加到答案中(那些 R 的車也會撞到)&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 895 - Maximum Frequency Stack</title>
    <link href="http://oj.roy4801.tw/2022/03/20/leetcode/895/"/>
    <id>http://oj.roy4801.tw/2022/03/20/leetcode/895/</id>
    <published>2022-03-20T04:55:18.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-frequency-stack/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目要你實作一個像 stack 的資料結構，但與單純的 stack 不同的是: pop 是看當前元素個數最多的決定的，如果個數相同則越靠近 top 越先被 pop 出來，例如: &lt;code&gt;[5,7,5,7,4,5]&lt;/code&gt; 則 pop 順序會是 &lt;code&gt;[5,7,5,4,7,5]&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;用一個 heap 維護 &lt;code&gt;(數字個數, 位置, 數字值)&lt;/code&gt; 的結構，另外還要維護一個 數字對到個數的結構，和當前的位置。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="stack" scheme="http://oj.roy4801.tw/tags/stack/"/>
    
    <category term="ordered set" scheme="http://oj.roy4801.tw/tags/ordered-set/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 946 - Validate Stack Sequences</title>
    <link href="http://oj.roy4801.tw/2022/03/17/leetcode/946/"/>
    <id>http://oj.roy4801.tw/2022/03/17/leetcode/946/</id>
    <published>2022-03-17T10:03:35.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/validate-stack-sequences/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你兩個整數陣列 &lt;code&gt;pushed&lt;/code&gt; 和 &lt;code&gt;popped&lt;/code&gt;，問你 &lt;code&gt;pushed&lt;/code&gt; 能不能透過 stack 操作後轉成 &lt;code&gt;popped&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;用一個 stack 模擬 &lt;code&gt;pushed&lt;/code&gt; 如何被 push 和 pop 轉成 &lt;code&gt;popped&lt;/code&gt;&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Stack" scheme="http://oj.roy4801.tw/tags/Stack/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 35 - Search Insert Position</title>
    <link href="http://oj.roy4801.tw/2022/03/15/leetcode/35/"/>
    <id>http://oj.roy4801.tw/2022/03/15/leetcode/35/</id>
    <published>2022-03-15T11:42:25.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/search-insert-position/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你排序好的陣列 &lt;code&gt;nums&lt;/code&gt; 和整數 &lt;code&gt;target&lt;/code&gt;，問你如果 &lt;code&gt;target&lt;/code&gt; 存在於 &lt;code&gt;nums&lt;/code&gt; 中則回傳 index；反之，回傳他可能插入的第一個 index&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;其實是問你陣列中第一個 &amp;gt;= target 的數字之位置，二分搜裸題&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="binary search" scheme="http://oj.roy4801.tw/tags/binary-search/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1249 - Minimum Remove to Make Valid Parentheses</title>
    <link href="http://oj.roy4801.tw/2022/03/15/leetcode/1249/"/>
    <id>http://oj.roy4801.tw/2022/03/15/leetcode/1249/</id>
    <published>2022-03-15T11:04:50.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個字串，其中包含了 &lt;code&gt;(&lt;/code&gt; 和 &lt;code&gt;)&lt;/code&gt;，問你刪除不定數量的括弧後使得括弧平衡(每個 &lt;code&gt;(&lt;/code&gt; 都有其對應的 &lt;code&gt;)&lt;/code&gt;)，字串長怎樣。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;先掃一遍，用 stack 匹配括弧，遇到 &lt;code&gt;(&lt;/code&gt; push、遇到 &lt;code&gt;)&lt;/code&gt; pop (如果不是空)，最後 stack 剩下的會是沒匹配到的&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="stack" scheme="http://oj.roy4801.tw/tags/stack/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2201 - Count Artifacts That Can Be Extracted</title>
    <link href="http://oj.roy4801.tw/2022/03/14/leetcode/2201/"/>
    <id>http://oj.roy4801.tw/2022/03/14/leetcode/2201/</id>
    <published>2022-03-14T01:25:41.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/count-artifacts-that-can-be-extracted/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個 n x n 的 grid 並給你一堆寶藏的地點 &lt;code&gt;artifact[i] = [r1_i, c1_i, r2_i, c2_i]&lt;/code&gt; 其中 &lt;code&gt;(r1, c1)&lt;/code&gt; 與 &lt;code&gt;(r2, c2)&lt;/code&gt; 代表寶藏的左上到右下&lt;br&gt;
接著給你挖掘的座標 &lt;code&gt;dig[i] = [r_i, c_i]&lt;/code&gt; 問你最後挖了幾個寶藏(一個寶藏要被挖出 &amp;lt;=&amp;gt; 挖出寶藏所佔的所有格子)&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;時間複雜度: $&#92;mathcal{O}(n^2)$&lt;/li&gt;
&lt;li&gt;空間複雜度: $&#92;mathcal{O}(n^2)$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="2D 格子" scheme="http://oj.roy4801.tw/tags/2D-%E6%A0%BC%E5%AD%90/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2200 - Find All K-Distant Indices in an Array</title>
    <link href="http://oj.roy4801.tw/2022/03/14/leetcode/2200/"/>
    <id>http://oj.roy4801.tw/2022/03/14/leetcode/2200/</id>
    <published>2022-03-14T00:43:24.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-all-k-distant-indices-in-an-array/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個整數陣列 &lt;code&gt;num&lt;/code&gt; 和兩個整數 &lt;code&gt;key&lt;/code&gt;, &lt;code&gt;k&lt;/code&gt;。數列中所有是 &lt;code&gt;key&lt;/code&gt; 的數字的前後 &lt;code&gt;k&lt;/code&gt; 個數字所包含的區間是 k-distant index&lt;br&gt;
e.g. &lt;code&gt;nums=[1, 2, 3, 4], key=2, k=1 =&amp;gt; k-distant = [0, 1, 2]&lt;/code&gt;，題目要你回傳 k-distant index&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 1000&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= nums[i] &amp;lt;= 1000&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= k &amp;lt;= nums.length&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 138 - Copy List with Random Pointer</title>
    <link href="http://oj.roy4801.tw/2022/03/12/leetcode/138/"/>
    <id>http://oj.roy4801.tw/2022/03/12/leetcode/138/</id>
    <published>2022-03-12T22:13:34.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/copy-list-with-random-pointer/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給一個 singly linked list 但是每個 node 除了 &lt;code&gt;val&lt;/code&gt; 之外，還有一個 &lt;code&gt;random&lt;/code&gt; pointer 指向其他 node&lt;br&gt;
要你回傳 deep copy&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;用 dictionary 把舊的 node 映射到新的 node&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 141 - Linked List Cycle</title>
    <link href="http://oj.roy4801.tw/2022/03/09/leetcode/141/"/>
    <id>http://oj.roy4801.tw/2022/03/09/leetcode/141/</id>
    <published>2022-03-09T02:21:54.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/linked-list-cycle/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/nqGryLZ.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;題目給你一個單向鏈結串列(Singly linked-list)，問你有沒有存在環(Cycle)?&lt;/p&gt;
&lt;p&gt;follow-up: 可以在 $&#92;mathcal{O}(1)$ 空間複雜度達成?&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="cycle detection" scheme="http://oj.roy4801.tw/tags/cycle-detection/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2196 - Create Binary Tree From Descriptions</title>
    <link href="http://oj.roy4801.tw/2022/03/07/leetcode/2196/"/>
    <id>http://oj.roy4801.tw/2022/03/07/leetcode/2196/</id>
    <published>2022-03-07T07:03:50.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/create-binary-tree-from-descriptions/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一堆邊 &lt;code&gt;edges = [parent, child, isLeft]&lt;/code&gt; 要你回傳建出來的圖。&lt;br&gt;
&lt;code&gt;isLeft==1&lt;/code&gt; 代表 child 是 parent 的左子節點；反之 &lt;code&gt;isLeft==0&lt;/code&gt;，代表 child 是 parent 的右子節點。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;E = edges&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= E.length &amp;lt;= 104&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;E[i].length == 3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= parent, child &amp;lt;= 105&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= isLeft &amp;lt;= 1&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 2194 - Cells in a Range on an Excel Sheet</title>
    <link href="http://oj.roy4801.tw/2022/03/07/leetcode/2194/"/>
    <id>http://oj.roy4801.tw/2022/03/07/leetcode/2194/</id>
    <published>2022-03-07T06:51:30.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/cells-in-a-range-on-an-excel-sheet/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/HDknepz.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;題目給你一組excel 的表格字串 e.g. &lt;code&gt;&amp;quot;K1:L2&amp;quot;&lt;/code&gt; 問你能不能像 excel 那樣輸出表格順序 e.g. &lt;code&gt;[&amp;quot;K1&amp;quot;,&amp;quot;K2&amp;quot;,&amp;quot;L1&amp;quot;,&amp;quot;L2&amp;quot;]&lt;/code&gt;&lt;br&gt;
行由一個大寫英文字母表示；列由一個正整數表示。題目要求回傳表格的陣列&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;s.length == 5&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&#39;A&#39; &amp;lt;= s[0] &amp;lt;= s[3] &amp;lt;= &#39;Z&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&#39;1&#39; &amp;lt;= s[1] &amp;lt;= s[4] &amp;lt;= &#39;9&#39;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 799 - Champagne Tower</title>
    <link href="http://oj.roy4801.tw/2022/03/04/leetcode/799/"/>
    <id>http://oj.roy4801.tw/2022/03/04/leetcode/799/</id>
    <published>2022-03-04T21:53:59.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/champagne-tower/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/pGB4eNJ.png&quot; alt&gt;&lt;/p&gt;
&lt;p&gt;題目說有 &lt;code&gt;n&lt;/code&gt; 個杯子，從最上面的那個杯子開始倒水，總共倒 &lt;code&gt;p&lt;/code&gt; 杯水，每個杯子只要到一杯就滿，往滿的水杯中倒水會往兩側溢出 &lt;code&gt;1/2&lt;/code&gt; 的水，&lt;br&gt;
給你倒水的總杯數 &lt;code&gt;p&lt;/code&gt; 問你第 &lt;code&gt;r&lt;/code&gt; 列第 &lt;code&gt;c&lt;/code&gt; 個的水杯的狀態。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= p &amp;lt;= 109&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= r &amp;lt;= c &amp;lt; 100&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 56 - Merge Intervals</title>
    <link href="http://oj.roy4801.tw/2022/03/02/leetcode/56/"/>
    <id>http://oj.roy4801.tw/2022/03/02/leetcode/56/</id>
    <published>2022-03-02T22:23:14.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/merge-intervals/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一堆區間，要你重疊的區間合併並回傳整個陣列&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;把區間由小到大排序後，把相鄰重疊的區間合併&lt;br&gt;
官方題解有為何排序後可以合併的區間是連續的證明 &lt;a href=&quot;https://leetcode-cn.com/problems/merge-intervals/solution/he-bing-qu-jian-by-leetcode-solution/&quot;&gt;Link&lt;/a&gt;&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 392 - Is Subsequence</title>
    <link href="http://oj.roy4801.tw/2022/03/02/leetcode/392/"/>
    <id>http://oj.roy4801.tw/2022/03/02/leetcode/392/</id>
    <published>2022-03-02T20:21:52.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/is-subsequence/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給兩個字串 &lt;code&gt;s&lt;/code&gt; 和 &lt;code&gt;t&lt;/code&gt; 問 &lt;code&gt;s&lt;/code&gt; 是不是 &lt;code&gt;t&lt;/code&gt; 的子序列(Subsequence)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= s.length &amp;lt;= 100&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0 &amp;lt;= t.length &amp;lt;= 104&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Follow-up: 當 s.length &amp;gt;= 10^9 時要怎麼做&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 338 - Counting Bits</title>
    <link href="http://oj.roy4801.tw/2022/03/01/leetcode/338/"/>
    <id>http://oj.roy4801.tw/2022/03/01/leetcode/338/</id>
    <published>2022-03-01T13:16:41.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/counting-bits/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個整數 &lt;code&gt;n&lt;/code&gt; 問你從 $[0, n]$ binary 中一的個數，輸出在 list 中。限制: $0 &#92;leq n &#92;leq 10^5$&lt;/p&gt;
&lt;p&gt;follow-up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;在時間複雜度 $&#92;mathcal{O}(N)$ 下做到且掃一次就完成&lt;/li&gt;
&lt;li&gt;避免使用 builtin function e.g. &lt;code&gt;__builtin_popcount()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="Bit Manipulation" scheme="http://oj.roy4801.tw/tags/Bit-Manipulation/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1 - Two Sum</title>
    <link href="http://oj.roy4801.tw/2022/03/01/leetcode/1/"/>
    <id>http://oj.roy4801.tw/2022/03/01/leetcode/1/</id>
    <published>2022-03-01T02:04:12.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/two-sum&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個整數陣列 &lt;code&gt;nums&lt;/code&gt; 和一個正數 &lt;code&gt;target&lt;/code&gt;，問你哪兩個數字加起來等於 &lt;code&gt;target&lt;/code&gt;。&lt;br&gt;
每組輸入一定都會有解，回傳 index 即可。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;$&#92;mathcal{O}(N^2)$ 的解很簡單，直接做就好。$&#92;mathcal{O}(N&#92;log{N})$的解，先記錄數字對應到的位置(同個數字可能出現在多個位置)，接著遍歷每個數字 &lt;code&gt;i&lt;/code&gt;，看看 &lt;code&gt;target - n[i]&lt;/code&gt; 有沒有在裏頭，如果有且沒挑過的話，則找到答案&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 228 - Summary Ranges</title>
    <link href="http://oj.roy4801.tw/2022/02/28/leetcode/228/"/>
    <id>http://oj.roy4801.tw/2022/02/28/leetcode/228/</id>
    <published>2022-02-28T18:28:52.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/summary-ranges/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個&lt;strong&gt;排序過&lt;/strong&gt;的整數陣列，要你回傳覆蓋整個陣列的所有區間。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;掃一遍，檢查當前跟前一個是否只差一，如果是代表區間繼續；不是則輸出區間並更新目前區間左界。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="array" scheme="http://oj.roy4801.tw/tags/array/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 165 - Compare Version Numbers</title>
    <link href="http://oj.roy4801.tw/2022/02/25/leetcode/165/"/>
    <id>http://oj.roy4801.tw/2022/02/25/leetcode/165/</id>
    <published>2022-02-25T22:03:00.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/compare-version-numbers/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你兩個版本號，要你比較大小&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照做即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="string" scheme="http://oj.roy4801.tw/tags/string/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 169 - Majority Element</title>
    <link href="http://oj.roy4801.tw/2022/02/24/leetcode/169/"/>
    <id>http://oj.roy4801.tw/2022/02/24/leetcode/169/</id>
    <published>2022-02-24T00:11:56.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/majority-element/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個陣列 &lt;code&gt;nums&lt;/code&gt;，回傳出現次數超過 $&#92;lfloor &#92;frac{n}{2} &#92;rfloor$ 的的那個數字(眾數)。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;直覺做就是先建表紀錄每個數字出現的次數，接著排序拿最大即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="hashmap" scheme="http://oj.roy4801.tw/tags/hashmap/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 133 - Clone Graph</title>
    <link href="http://oj.roy4801.tw/2022/02/23/leetcode/133/"/>
    <id>http://oj.roy4801.tw/2022/02/23/leetcode/133/</id>
    <published>2022-02-23T21:52:52.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/clone-graph/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一張圖，要你 Deep copy 一份並回傳。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;BFS 遍歷一次，邊走邊複製。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="BFS" scheme="http://oj.roy4801.tw/tags/BFS/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 171 - Excel Sheet Column Number</title>
    <link href="http://oj.roy4801.tw/2022/02/22/leetcode/171/"/>
    <id>http://oj.roy4801.tw/2022/02/22/leetcode/171/</id>
    <published>2022-02-22T17:01:42.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/excel-sheet-column-number/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個字串 &lt;code&gt;S&lt;/code&gt; 由大寫英文字母組成，令 &lt;code&gt;A=1, B=2, ..., Z=26, AA=27, AB=28, ...&lt;/code&gt; ，要你算出並回傳數值。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照做即可&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1288 - Remove Covered Intervals</title>
    <link href="http://oj.roy4801.tw/2022/02/20/leetcode/1288/"/>
    <id>http://oj.roy4801.tw/2022/02/20/leetcode/1288/</id>
    <published>2022-02-20T17:58:40.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/remove-covered-intervals/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個由正整數構成的區間，&lt;code&gt;intervals[i] = [li, ri]&lt;/code&gt;，如果區間 &lt;code&gt;[a, b)&lt;/code&gt; 被 &lt;code&gt;[c, d)&lt;/code&gt; 覆蓋，則代表 $c &amp;lt;= a$ 且 $b &amp;lt;= d$&lt;br&gt;
要你回傳刪掉被覆蓋的區間後，剩下區間的個數。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;N = intervals.size()&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;$1 &#92;leq N &#92;leq 1000$&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;區間範圍: $0 &#92;leq l_i &#92;leq r_i &#92;leq 10^5$&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="sorting" scheme="http://oj.roy4801.tw/tags/sorting/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1675 - Minimize Deviation in Array</title>
    <link href="http://oj.roy4801.tw/2022/02/20/leetcode/1675/"/>
    <id>http://oj.roy4801.tw/2022/02/20/leetcode/1675/</id>
    <published>2022-02-20T05:33:33.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/minimize-deviation-in-array/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一列正整數 &lt;code&gt;N&lt;/code&gt; ，你可以對數列中的每個元素執行兩種操作:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;如果 &lt;code&gt;N[i]&lt;/code&gt; 是偶數，可以除 2&lt;/li&gt;
&lt;li&gt;如果 &lt;code&gt;N[i]&lt;/code&gt; 是奇數，可以乘 2&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;定義 &lt;code&gt;deviation&lt;/code&gt; 是數列中的最大和最小之差 &lt;code&gt;max(N) - min(N)&lt;/code&gt;&lt;br&gt;
問你經過幾次操作後，最小的 &lt;code&gt;deviation&lt;/code&gt; 是多少?&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="greedy" scheme="http://oj.roy4801.tw/tags/greedy/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 127 - Word Ladder</title>
    <link href="http://oj.roy4801.tw/2022/02/20/leetcode/127/"/>
    <id>http://oj.roy4801.tw/2022/02/20/leetcode/127/</id>
    <published>2022-02-20T05:07:18.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/word-ladder/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;一個字串能夠從 &lt;code&gt;beginWord&lt;/code&gt; 轉換成 &lt;code&gt;endWord&lt;/code&gt; 稱作 &lt;code&gt;transformation sequence&lt;/code&gt;&lt;br&gt;
e.g. &lt;code&gt;beginWord -&amp;gt; s1 -&amp;gt; s2 -&amp;gt; ... -&amp;gt; sk&lt;/code&gt;，今天題目給你一個 &lt;code&gt;wordList&lt;/code&gt; 問你從 &lt;code&gt;beginWord&lt;/code&gt; 到 &lt;code&gt;endWord&lt;/code&gt; 總共幾個字串，並且要&lt;strong&gt;最短&lt;/strong&gt;的。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;其中每個字串只差一個字元 =&amp;gt; 相差一個字元才能轉換&lt;/li&gt;
&lt;li&gt;轉換的字串都在 &lt;code&gt;wordList&lt;/code&gt; 裏頭&lt;/li&gt;
&lt;li&gt;&lt;code&gt;beginWord&lt;/code&gt; 不一定要在 &lt;code&gt;wordList&lt;/code&gt; 裏頭&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Hard" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Hard/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="graph" scheme="http://oj.roy4801.tw/tags/graph/"/>
    
    <category term="bfs" scheme="http://oj.roy4801.tw/tags/bfs/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 39 - Combination Sum</title>
    <link href="http://oj.roy4801.tw/2022/02/19/leetcode/39/"/>
    <id>http://oj.roy4801.tw/2022/02/19/leetcode/39/</id>
    <published>2022-02-19T04:17:09.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/combination-sum/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一組數字 &lt;code&gt;candidates&lt;/code&gt; 和一個數字 &lt;code&gt;target&lt;/code&gt; ，問你能用&lt;code&gt;candidates&lt;/code&gt;中的元素組成&lt;strong&gt;不重複&lt;/strong&gt;的組合，且相加要等於 &lt;code&gt;T&lt;/code&gt;。相同的數字可以出現無限次&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1 &amp;lt;= candidates.size() &amp;lt;= 30&lt;/li&gt;
&lt;li&gt;1 &amp;lt;= candidates[i] &amp;lt;= 200&lt;/li&gt;
&lt;li&gt;1 &amp;lt;= T &amp;lt;= 500&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 402 - Remove K Digits</title>
    <link href="http://oj.roy4801.tw/2022/02/19/leetcode/402/"/>
    <id>http://oj.roy4801.tw/2022/02/19/leetcode/402/</id>
    <published>2022-02-19T02:10:49.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/remove-k-digits/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你一個只有非負整數的字串 &lt;code&gt;num&lt;/code&gt; 和整數 &lt;code&gt;k&lt;/code&gt;，要你回傳刪掉 &lt;code&gt;k&lt;/code&gt; 個數字後，之中最小的整數&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;Input: num = &amp;quot;1432219&amp;quot;, k = 3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;Output: &amp;quot;1219&amp;quot;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="monotonic stack" scheme="http://oj.roy4801.tw/tags/monotonic-stack/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 104 - Maximum Depth of Binary Tree</title>
    <link href="http://oj.roy4801.tw/2022/02/17/leetcode/104/"/>
    <id>http://oj.roy4801.tw/2022/02/17/leetcode/104/</id>
    <published>2022-02-17T15:34:14.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/maximum-depth-of-binary-tree&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給一個二元樹，要你回傳樹高&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;DFS 遍歷整顆樹，可用 backtracking 到 leaf 時紀錄走了多深，找最大即可&lt;br&gt;
遍歷時可拆成，&lt;code&gt;max( dfs(左子樹), dfs(右子樹) )&lt;/code&gt;&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="bst" scheme="http://oj.roy4801.tw/tags/bst/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 24 - Swap Nodes in Pairs</title>
    <link href="http://oj.roy4801.tw/2022/02/16/leetcode/24/"/>
    <id>http://oj.roy4801.tw/2022/02/16/leetcode/24/</id>
    <published>2022-02-16T15:31:32.000Z</published>
    <updated>2024-07-04T14:41:54.805Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/swap-nodes-in-pairs/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給一個 Singly linked list 要你把每兩個兩個 swap 一遍，但不能只 swap value&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;照做即可，注意邊界 e.g. list 沒有 node 的狀態、list 只有一個 node 的狀態&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="linked list" scheme="http://oj.roy4801.tw/tags/linked-list/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 78 - Subsets</title>
    <link href="http://oj.roy4801.tw/2022/02/13/leetcode/78/"/>
    <id>http://oj.roy4801.tw/2022/02/13/leetcode/78/</id>
    <published>2022-02-13T21:55:26.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/subsets/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給一個 array size = $N$ e.g. &lt;code&gt;[1, 2, 3]&lt;/code&gt; 要回傳它的所有可能的子集合(Power set) e.g. &lt;code&gt;[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;如果用 bit 來表示位置 $i$ 是否有出現，則問題就是數數字 $[0, 2^N]$，每個數字代表一種子集合的狀態&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Medium" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Medium/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="backtracking" scheme="http://oj.roy4801.tw/tags/backtracking/"/>
    
  </entry>
  
  <entry>
    <title>Uva 679 - Dropping Balls</title>
    <link href="http://oj.roy4801.tw/2021/05/06/uva/uva679/"/>
    <id>http://oj.roy4801.tw/2021/05/06/uva/uva679/</id>
    <published>2021-05-06T23:03:09.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://onlinejudge.org/index.php?option=onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=620&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有 $K$ 顆球從一顆有高度 $D$ 的完全二元樹上落下，從根節點一直落到葉節點，其中「非葉節點」都儲存個 bool 值(一開始是 false)，當一顆球經過該節點時，就會反轉該 bool 值。當每顆球經過該「非葉節點」時，如果 bool 值是 false，則走左子樹；反之，如果 bool 值是 true，則走右子樹。 問你寫程式回答當第 $I$ 顆球最後停在的節點 $P$ 是多少?&lt;/p&gt;
&lt;p&gt;$2 &#92;le D &#92;le 20&#92;text{, and } 1 &#92;le I &#92;le 524288$&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;shu-ru&quot;&gt;輸入&lt;/span&gt;&lt;a href=&quot;#shu-ru&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 977 - Squares of a Sorted Array</title>
    <link href="http://oj.roy4801.tw/2021/03/03/leetcode/977/"/>
    <id>http://oj.roy4801.tw/2021/03/03/leetcode/977/</id>
    <published>2021-03-03T03:42:12.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/squares-of-a-sorted-array/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個遞增排序的&lt;/p&gt;
&lt;p&gt;follow-up: 用 $&#92;mathcal{O}(N)$ 實作&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
    <category term="雙指標" scheme="http://oj.roy4801.tw/tags/%E9%9B%99%E6%8C%87%E6%A8%99/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 1295 - Find Numbers with Even Number of Digits</title>
    <link href="http://oj.roy4801.tw/2021/03/03/leetcode/1295/"/>
    <id>http://oj.roy4801.tw/2021/03/03/leetcode/1295/</id>
    <published>2021-03-03T03:26:28.000Z</published>
    <updated>2024-07-04T14:41:54.801Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/find-numbers-with-even-number-of-digits/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;題目給你一個整數陣列，問你裏頭有幾個數字是偶數個位數。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;時間複雜度: $&#92;mathcal{O}(NM)$
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;N=nums.size()&lt;/code&gt;, &lt;code&gt;M=nums[i].length()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;空間複雜度: $&#92;mathcal{O}(1)$&lt;/li&gt;
&lt;/ul&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Leetcode 485 - Max Consecutive Ones</title>
    <link href="http://oj.roy4801.tw/2021/03/03/leetcode/485/"/>
    <id>http://oj.roy4801.tw/2021/03/03/leetcode/485/</id>
    <published>2021-03-03T00:17:00.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://leetcode.com/problems/max-consecutive-ones/&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給一個由 &lt;code&gt;0&lt;/code&gt; 和 &lt;code&gt;1&lt;/code&gt; 組成的陣列 &lt;code&gt;nums&lt;/code&gt;，問最長連續的 1 是多少&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;掃一遍，遇到 0 就把 counter 歸零，找最大&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/"/>
    
    <category term="Easy" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Leetcode/Easy/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Leetcode" scheme="http://oj.roy4801.tw/tags/Leetcode/"/>
    
  </entry>
  
  <entry>
    <title>Uva 1587 - Box</title>
    <link href="http://oj.roy4801.tw/2019/09/11/uva/uva1587/"/>
    <id>http://oj.roy4801.tw/2019/09/11/uva/uva1587/</id>
    <published>2019-09-11T23:56:25.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=4462&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給你6個寬$w_i$高$h_i$的紙板，問可不可以組成一個長方體&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;組成一個長方體的紙板可以分成三組（相對一組），有三種情況：相異、兩同ㄧ異、全部相同。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 202 - Repeating Decimals</title>
    <link href="http://oj.roy4801.tw/2019/09/10/uva/uva202/"/>
    <id>http://oj.roy4801.tw/2019/09/10/uva/uva202/</id>
    <published>2019-09-10T22:22:48.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;略&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;跟&lt;a href=&quot;/2019/09/10/uva/uva202&quot;&gt;uva 275&lt;/a&gt;差不多，只是輸出更複雜了點&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 275 - Expanding Fractions</title>
    <link href="http://oj.roy4801.tw/2019/09/10/uva/uva275/"/>
    <id>http://oj.roy4801.tw/2019/09/10/uva/uva275/</id>
    <published>2019-09-10T22:16:22.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=211&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;輸入兩個數字a, b，要算a/b的小數，如果有循環小數部分出現，則只輸出一次&lt;br&gt;
每筆輸出最後要輸出循環小數的長度（如果沒有則輸出&lt;code&gt;This expansion terminates.&lt;/code&gt;)&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;模擬長除法，一位一位除&lt;br&gt;
輸出很鳥（注意換行，每行最多50字，小數點也算）&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 10226 - Hardwood Species</title>
    <link href="http://oj.roy4801.tw/2019/06/26/uva/uva10226/"/>
    <id>http://oj.roy4801.tw/2019/06/26/uva/uva10226/</id>
    <published>2019-06-26T15:52:43.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;category=24&amp;amp;page=show_problem&amp;amp;problem=1167&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有多種樹的名字，你要輸出每種樹佔的比例（按名稱字典序）&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;map&lt;/code&gt;練習題&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 793 - Network Connections</title>
    <link href="http://oj.roy4801.tw/2019/06/26/uva/uva793/"/>
    <id>http://oj.roy4801.tw/2019/06/26/uva/uva793/</id>
    <published>2019-06-26T15:43:05.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=734&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一堆電腦用網路連著，今天你是網管，你想知道電腦 $i$ 跟電腦 $j$ 是否有相連（在同個網路內），並且你也可以將兩台電腦相連。有兩個操作：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;相連 &lt;code&gt;c i j&lt;/code&gt;&lt;br&gt;
將電腦$i$和電腦$j$相連&lt;/li&gt;
&lt;li&gt;查詢 &lt;code&gt;q i j&lt;/code&gt;&lt;br&gt;
查詢電腦$i$和電腦$j$是否相連&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;程式最後輸出查詢&lt;code&gt;有相連,沒相連&lt;/code&gt;&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 10033 - Interpreter</title>
    <link href="http://oj.roy4801.tw/2019/06/24/uva/uva10033/"/>
    <id>http://oj.roy4801.tw/2019/06/24/uva/uva10033/</id>
    <published>2019-06-24T15:23:00.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=974&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;http://rubyacm.blogspot.com/2010/08/10033-interpreter.html&quot;&gt;http://rubyacm.blogspot.com/2010/08/10033-interpreter.html&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;挺有趣的一題，要寫個小VM執行code，算出執行了幾個指令。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 10004 - Bicoloring</title>
    <link href="http://oj.roy4801.tw/2019/06/23/uva/uva10004/"/>
    <id>http://oj.roy4801.tw/2019/06/23/uva/uva10004/</id>
    <published>2019-06-23T00:28:43.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=945&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給定任意的圖形，問可不可以在每個點上著不同兩種的顏色，並且相同顏色的點不相鄰。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;沒有自環&lt;/li&gt;
&lt;li&gt;無向圖&lt;/li&gt;
&lt;li&gt;強連通&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
    <category term="dfs" scheme="http://oj.roy4801.tw/tags/dfs/"/>
    
  </entry>
  
  <entry>
    <title>Uva 1203 - Argus</title>
    <link href="http://oj.roy4801.tw/2019/06/22/uva/uva1203/"/>
    <id>http://oj.roy4801.tw/2019/06/22/uva/uva1203/</id>
    <published>2019-06-22T23:54:21.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=onlinejudge&amp;amp;page=show_problem&amp;amp;problem=3644&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有個程式要記錄眾多的事件，使用者可以輸入指令註冊要監測的事件，指令要包含事件的ID(Q_num)跟週期(Period)，格式如下：&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;Register Q_num Period&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;代表要註冊&lt;code&gt;Q_num&lt;/code&gt;事件，每&lt;code&gt;Period&lt;/code&gt;秒執行一次。而程式可以一次監測多個事件（用指令註冊），你要寫程式輸出前$k$個執行的事件。&lt;br&gt;
(如果在同一秒有多個事件，則以&lt;code&gt;Q_num&lt;/code&gt;遞增排序)&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
    <category term="priority queue" scheme="http://oj.roy4801.tw/tags/priority-queue/"/>
    
  </entry>
  
  <entry>
    <title>Uva 526 - String Distance and Transform Process</title>
    <link href="http://oj.roy4801.tw/2019/06/14/uva/uva526/"/>
    <id>http://oj.roy4801.tw/2019/06/14/uva/uva526/</id>
    <published>2019-06-14T18:30:55.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=467&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;字串距離是一個代表兩個字串的非負整數。接著要轉換(transform)$a$字串至$b$字串，有三種操作：插入(Insert)、刪除(Delete)、及取代（Replace)。&lt;br&gt;
字串距離就是轉換的數量，求任意$a$字串轉換至$b$字串的字串距離及如何轉換的。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;shu-ru&quot;&gt;輸入&lt;/span&gt;&lt;a href=&quot;#shu-ru&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;每筆case有兩行字串$a$、$b$，以EOF結尾，字串的長度不超過$80$&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
  </entry>
  
  <entry>
    <title>Uva 11059 - Maximum Product</title>
    <link href="http://oj.roy4801.tw/2019/05/18/uva/uva11059/"/>
    <id>http://oj.roy4801.tw/2019/05/18/uva/uva11059/</id>
    <published>2019-05-18T21:40:29.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=onlinejudge&amp;amp;Itemid=99999999&amp;amp;page=show_problem&amp;amp;category=0&amp;amp;problem=2000&amp;amp;mosmsg=Submission+received+with+ID+23356954&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;給定一個序列 $S = {S_1, S_2, …, S_n}$ ，找一個連續的子序列使得相乘最大。&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;這題可以直接做，也可以DP&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 11078 - Open Credit System</title>
    <link href="http://oj.roy4801.tw/2019/05/18/uva/uva11078/"/>
    <id>http://oj.roy4801.tw/2019/05/18/uva/uva11078/</id>
    <published>2019-05-18T15:29:18.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;category=0&amp;amp;problem=2019&amp;amp;mosmsg=Submission+received+with+ID+23355296&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;(簡化)&lt;br&gt;
有一組數列($a_i$)，對所有$i&amp;lt;j$，求最大的$a_i - a_j$&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;$&#92;mathcal{O}(n^2)$暴力會TLE，但觀察可以發現，對於每個$a_j$，如果$a_i - a_j$要最大，那$a_i$一定越大越好，所以可以直接維護一個最大值($M$)，代表從$1 &#92;sim i$的最大。&lt;br&gt;
只要掃一遍，就得到答案。($&#92;mathcal{O}(n)$)&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 10685 - Nature</title>
    <link href="http://oj.roy4801.tw/2019/05/17/uva/uva10685/"/>
    <id>http://oj.roy4801.tw/2019/05/17/uva/uva10685/</id>
    <published>2019-05-17T23:37:37.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=onlinejudge&amp;amp;page=show_problem&amp;amp;problem=1626&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;大自然存在著食物鏈，體型大的動物吃小動物，小動物吃植物，死亡的動物被分解，作為植物的養分。&lt;br&gt;
而你的任務是給定一組動物，求出最大的食物鏈動物數量為何？假如A吃B，你可以認定它們在同個食物鏈裡。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;shu-ru&quot;&gt;輸入&lt;/span&gt;&lt;a href=&quot;#shu-ru&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;每筆測資開頭有兩個整數 $C$ 代表有幾隻動物和 $R$ 有幾組關係；接著 $C$ 列，每列有一個名字（字串、只有小寫、不超過30字）；再接著有 $R$ 列，每列有兩個名字，代表第二個動物吃第一個動物。&lt;br&gt;
你可以認定沒有一隻動物是自己的獵食者。&lt;br&gt;
輸入終止在 $C = R = 0$ ，每筆測資間有空白列。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 136 - Ugly Number</title>
    <link href="http://oj.roy4801.tw/2019/02/24/uva/uva136/"/>
    <id>http://oj.roy4801.tw/2019/02/24/uva/uva136/</id>
    <published>2019-02-24T13:26:12.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=onlinejudge&amp;amp;page=show_problem&amp;amp;problem=72&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;&lt;code&gt;Ulgy Number&lt;/code&gt;是只有$2$、$3$、$5$質因數的數字。前11項是：&lt;br&gt;
$$&lt;br&gt;
1,&#92; 2,&#92; 3,&#92; 4,&#92; 5,&#92; 6,&#92; 8,&#92; 9,&#92; 10,&#92; 12,&#92; 15,&#92; …&lt;br&gt;
$$&lt;br&gt;
程式必須印出第1500項&lt;code&gt;ugly number&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;xiang-fa&quot;&gt;想法&lt;/span&gt;&lt;a href=&quot;#xiang-fa&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;第$n$個數字一定是前$n-1$個數字中，乘$2$、乘$3$、乘$5$得來的。&lt;br&gt;
找數字的時候不用每個都從頭開始找，要找第$n$個數字，而這個數字勢必$&amp;gt;$第${n-1}$個數字，所以第&lt;code&gt;i, j, k&lt;/code&gt;個數字（分別乘$2$、乘$3$、乘$5$），至少要$&amp;gt;$第$n-1$個數字才有可能成為第$n$個數字。在這三種可能中，挑最小的便是第$n$個數字。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
    <category term="DP" scheme="http://oj.roy4801.tw/tags/DP/"/>
    
  </entry>
  
  <entry>
    <title>Uva 12100 - Printer Queue</title>
    <link href="http://oj.roy4801.tw/2019/02/08/uva/uva12100/"/>
    <id>http://oj.roy4801.tw/2019/02/08/uva/uva12100/</id>
    <published>2019-02-08T14:34:58.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;category=&amp;amp;problem=3252&amp;amp;mosmsg=Submission+received+with+ID+22756147&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有台印表機，有 $n$ 件工作等待列印($1 &#92;le n &#92;le 100$)，你排在第 $m$ 號位置($0 &#92;le m &#92;le {n-1}$)，位置從零開始。&lt;br&gt;
由於實在是太多人印了，所以把每件工作都加上優先權，從1~9代表低到高。&lt;br&gt;
對於是否要列印有特殊的規則：（假設佇列的頭是&lt;code&gt;job j&lt;/code&gt;）&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;如果佇列裡頭有比&lt;code&gt;job j&lt;/code&gt;還高優先的工作，則把&lt;code&gt;job j&lt;/code&gt;放到佇列最後頭。&lt;/li&gt;
&lt;li&gt;如果沒有，就執行&lt;code&gt;job j&lt;/code&gt;。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;你需要計算你必須花多少時間才能完成你的工作。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 11995 - I Can Guess the Data Structure!</title>
    <link href="http://oj.roy4801.tw/2019/02/07/uva/uva11995/"/>
    <id>http://oj.roy4801.tw/2019/02/07/uva/uva11995/</id>
    <published>2019-02-07T20:42:47.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=3146&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有種資料結構(你不知道是什麼）支援兩種操作：放入、拿出。給定一個操作的序列，你要寫支程式推測出是哪種資料結構（&lt;code&gt;stack&lt;/code&gt;, &lt;code&gt;queue&lt;/code&gt;, &lt;code&gt;priority queue&lt;/code&gt;），不確定則輸出不確定，不知道輸出不知道。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;shu-ru&quot;&gt;輸入&lt;/span&gt;&lt;a href=&quot;#shu-ru&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;每筆測資第一行有數字 $n$($1 &#92;le n &#92;le{1000}$)，代表有 $n$ 筆操作&lt;br&gt;
接著 $n$ 行，每行有兩個數字，第一個數字是操作，&lt;code&gt;1&lt;/code&gt;是放入，後頭接著要放入的數字；&lt;code&gt;2&lt;/code&gt;是拿出，後頭接著要拿出的數字。&lt;br&gt;
以&lt;code&gt;EOF&lt;/code&gt;結尾&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 10935 - Throwing cards away I</title>
    <link href="http://oj.roy4801.tw/2019/02/03/uva/uva10935/"/>
    <id>http://oj.roy4801.tw/2019/02/03/uva/uva10935/</id>
    <published>2019-02-03T00:22:42.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=com_onlinejudge&amp;amp;Itemid=8&amp;amp;page=show_problem&amp;amp;problem=1876&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一疊卡，有標數字從$1$到$n$（頂端是$1$），每次從頂端丟掉一張卡片，再把一張卡片放到底部，直到卡片只剩一張。&lt;/p&gt;
&lt;h2&gt;&lt;span id=&quot;shu-ru&quot;&gt;輸入&lt;/span&gt;&lt;a href=&quot;#shu-ru&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;每行代表卡片的數量($n &#92;le{50} $)，以&lt;code&gt;0&lt;/code&gt;結尾。&lt;/p&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
  <entry>
    <title>Uva 402 - M*A*S*H</title>
    <link href="http://oj.roy4801.tw/2019/02/02/uva/uva402/"/>
    <id>http://oj.roy4801.tw/2019/02/02/uva/uva402/</id>
    <published>2019-02-02T23:54:28.000Z</published>
    <updated>2024-07-04T14:41:54.809Z</updated>
    
    
    <summary type="html">&lt;p&gt;&lt;a href=&quot;https://uva.onlinejudge.org/index.php?option=onlinejudge&amp;amp;page=show_problem&amp;amp;problem=343&quot;&gt;題目&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span id=&quot;problem&quot;&gt;Problem&lt;/span&gt;&lt;a href=&quot;#problem&quot; class=&quot;header-anchor&quot;&gt;#&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;有一排人（長度$N$），每次從一疊卡（20張）頂端抽出一張卡，點數$i$ 代表 列隊每$i$個人要去除。&lt;/p&gt;
&lt;p&gt;比如：列隊有&lt;code&gt;10&lt;/code&gt;人，抽到點數&lt;code&gt;3&lt;/code&gt;的卡，則：&lt;/p&gt;
&lt;figure class=&quot;highlight plaintext&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1 2 3 4 5 6 7 8 9 10&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;    x     x     x&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;    &lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;x 代表去除&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;</summary>
    
    
    
    <category term="解題區" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/categories/%E8%A7%A3%E9%A1%8C%E5%8D%80/Uva/"/>
    
    
    <category term="解題紀錄" scheme="http://oj.roy4801.tw/tags/%E8%A7%A3%E9%A1%8C%E7%B4%80%E9%8C%84/"/>
    
    <category term="Uva" scheme="http://oj.roy4801.tw/tags/Uva/"/>
    
  </entry>
  
</feed>
