<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Leetcode Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/category/leetcode/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/category/leetcode/</link>
	<description></description>
	<lastBuildDate>Sun, 19 May 2019 04:06:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>Leetcode Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/category/leetcode/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode Weekly Contest 137</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-137/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-137/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 19 May 2019 04:00:15 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[dynamic programming]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5206</guid>

					<description><![CDATA[<p>1046.&#160;Last Stone Weight Solution: Simulation (priority_queue) Time complexity: O(nlogn)Space complexity: O(n) [crayon-663cb2b3d40ab633274771/] 1047. Remove All Adjacent Duplicates In String Solution: Stack / Deque Time complexity:&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-137/">花花酱 LeetCode Weekly Contest 137</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2><strong>1046.&nbsp;Last Stone Weight</strong></h2>



<p>Solution: Simulation (priority_queue)</p>



<p>Time complexity: O(nlogn)<br>Space complexity: O(n)<br><br></p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int lastStoneWeight(vector&lt;int&gt;&amp; stones) {
    priority_queue&lt;int&gt; q;
    for (int s : stones)
      q.push(s);
    while (q.size() &gt; 1) {
      int x = q.top(); q.pop();
      int y = q.top(); q.pop();
      if (x == y) continue;
      q.push(abs(x - y));
    }
    return q.empty() ? 0 : q.top();
  }
};</pre>
</div></div>



<h2><strong>1047. Remove All Adjacent Duplicates In String</strong></h2>



<p>Solution: Stack / Deque</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  string removeDuplicates(string S) {
    deque&lt;char&gt; s;
    for (char c : S) {
      if (!s.empty() &amp;&amp; s.back() == c) s.pop_back();
      else s.push_back(c);
    }    
    return {begin(s), end(s)};
  }
};</pre>
</div></div>



<h2><strong>1048.&nbsp;Longest String Chain</strong></h2>



<p>Solution: DP</p>



<p>dp[i] := max length of chain of (A[0] ~ A[i-1])</p>



<p>dp[i] = max{dp[j] + 1} if A[j] is prederrsor of A[i], 1 &lt;= j &lt;i</p>



<p>Time complexity: O(n^2*l)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int longestStrChain(vector&lt;string&gt;&amp; words) {
    int n = words.size();
    sort(begin(words), end(words), [](const string&amp; a, const string&amp; b) { 
      return a.length() &lt; b.length();
    });
    vector&lt;int&gt; dp(n, 1);    
    for (int i = 0; i &lt; n; ++i)
      for (int j = 0; j &lt; i; ++j) 
        if (valid(words[j], words[i]))
          dp[i] = dp[j] + 1;
    return *max_element(begin(dp), end(dp));
  }
private:
  bool valid(const string&amp; a, const string&amp; b) {
    if (a.length() + 1 != b.length()) return false;
    int count = 0;
    for (int i = 0, j = 0; i &lt; a.length() &amp;&amp; j &lt; b.length();) {
      if (a[i] == b[j]) {
        ++i; ++j;
      } else { 
        ++count; ++j; 
      }
    }
    return count &lt;= 1;
  }
};</pre>
</div></div>



<h2><strong>1049.&nbsp;Last Stone Weight II</strong></h2>



<p><a href="https://leetcode.com/contest/weekly-contest-137/"></a>Solution: DP / target sum</p>



<p>Time complexity: O(n * S) = O(n * 100)</p>



<p>Space complexity: O(S) = O(100)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int lastStoneWeightII(vector&lt;int&gt;&amp; stones) {
    const int n = stones.size();
    const int max_sum = accumulate(begin(stones), end(stones), 0);    
    unordered_set&lt;int&gt; sums;
    sums.insert(stones[0]);
    sums.insert(-stones[0]);
    for (int i = 1; i &lt; n; ++i) {
      unordered_set&lt;int&gt; tmp;
      for (int s : sums) {
        tmp.insert(s + stones[i]);
        tmp.insert(s - stones[i]);
      }
      swap(tmp, sums);
    }
    int ans = INT_MAX;
    for (int s : sums)           
      ans = min(ans, abs(s));
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-137/">花花酱 LeetCode Weekly Contest 137</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-137/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 135 (1037, 1038, 1039, 1040)</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-135-1037-1038-1039-1040/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-135-1037-1038-1039-1040/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 05 May 2019 04:58:09 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5142</guid>

					<description><![CDATA[<p>LeetCode 1037.&#160;Valid Boomerang Solution: MathTime complexity: O(1)Space complexity: O(1) [crayon-663cb2b3d4608642963134/] LeetCode 1038. Binary Search Tree to Greater Sum Tree Solution: Recursion: right, root, left Time&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-135-1037-1038-1039-1040/">花花酱 LeetCode Weekly Contest 135 (1037, 1038, 1039, 1040)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2><strong>LeetCode  1037.&nbsp;Valid Boomerang</strong></h2>



<p>Solution: Math<br>Time complexity: O(1)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  bool isBoomerang(vector&lt;vector&lt;int&gt;&gt;&amp; points) {
    if (points[0] == points[1] || 
        points[1] == points[2] ||
        points[0] == points[2]) return false;
    int dx0 = points[0][0] - points[1][0];
    int dy0 = points[0][1] - points[1][1];
    int dx1 = points[0][0] - points[2][0];
    int dy1 = points[0][1] - points[2][1];    
    return dy0 * dx1 != dy1 * dx0;
  }
};</pre>
</div></div>



<h2><strong>LeetCode 1038. Binary Search Tree to Greater Sum Tree</strong><br></h2>



<p>Solution: Recursion: right, root, left</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  TreeNode* bstToGst(TreeNode* root) {     
    int s = 0;    
    function&lt;void(TreeNode*)&gt; dfs = [&amp;](TreeNode* n) {
      if (!n) return;
      dfs(n-&gt;right);
      n-&gt;val = s += n-&gt;val;      
      dfs(n-&gt;left);
    };
    dfs(root);
    return root;
  }
};</pre>
</div></div>



<h2><strong>1039. Minimum Score Triangulation of Polygon</strong><br></h2>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/05/1039.png" alt="" class="wp-image-5147" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/05/1039.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/05/1039-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/05/1039-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<p>Solution: DP</p>



<p>Init: dp[i][j] = 0 if  0 &lt;= j &#8211; i &lt;= 1<br>dp[i][j] := min score to triangulate A[i] ~ A[j]<br>dp[i][j] = min{dp[i][k] + dp[k][j] + A[i]*A[k]*A[j]), i &lt; k &lt; j<br>answer: dp[0][n &#8211; 1]</p>



<p>Time complexity: O(n^3)<br>Space complexity: O(n^2)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++/bottom-up</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  int minScoreTriangulation(vector&lt;int&gt;&amp; A) {
    const int n = A.size();
    vector&lt;vector&lt;int&gt;&gt; dp(n, vector&lt;int&gt;(n));
    for (int l = 3; l &lt;= n; ++l)
      for (int i = 0; i + l &lt;= n; ++i) {        
        int j = i + l - 1;
        dp[i][j] = INT_MAX;
        for (int k = i + 1; k &lt;= j - 1; ++k)
          dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + A[i] * A[k] * A[j]);
      }
    return dp[0][n - 1];
  }
};</pre>

</div><h2 class="tabtitle">C++/top-down</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  int minScoreTriangulation(vector&lt;int&gt;&amp; A) {
    const int n = A.size();
    vector&lt;vector&lt;int&gt;&gt; dp(n, vector&lt;int&gt;(n, INT_MAX));
    function&lt;int(int, int)&gt; solve = [&amp;](int i, int j) {
      if (j - i &lt;= 1) return 0;
      if (dp[i][j] != INT_MAX) return dp[i][j];
      dp[i][j] = INT_MAX;
      for (int k = i + 1; k &lt;= j - 1; ++k)
        dp[i][j] = min(dp[i][j], 
                       solve(i, k) + solve(k, j) + A[i] * A[k] * A[j]);
      return dp[i][j];  
    };
    return solve(0, n - 1);
  }
};</pre>

</div><h2 class="tabtitle">Python</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">&quot;Author: Huahua&quot;
from functools import lru_cache

class Solution:
  def minScoreTriangulation(self, A: List[int]) -&gt; int:     
    @lru_cache(None)
    def dp(i, j):      
      return 0 if j - i &lt;= 1 else min(dp(i, k) + dp(k, j) + A[i] * A[k] * A[j] for k in range(i + 1, j))
    return dp(0, len(A) - 1)</pre>
</div></div>



<h2><strong> 1040.&nbsp;Moving Stones Until Consecutive II</strong><br></h2>



<p>Solution: Sliding Window</p>



<p>Time complexity: O(nlogn)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  vector&lt;int&gt; numMovesStonesII(vector&lt;int&gt;&amp; stones) {
    const int n = static_cast&lt;int&gt;(stones.size());
    sort(begin(stones), end(stones));
    int max_steps = max(stones[n - 1] - stones[1] - n + 2,
                        stones[n - 2] - stones[0] - n + 2);
    int min_steps = INT_MAX;
    int i = 0;
    for (int j = 0; j &lt; n; ++j) {
      while (stones[j] - stones[i] &gt;= n) ++i;
      if (j - i + 1 == n - 1 &amp;&amp; stones[j] - stones[i] == n - 2)
        min_steps = min(min_steps, 2);
      else
        min_steps = min(min_steps, n - (j - i + 1));
    }
    return {min_steps, max_steps};
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-135-1037-1038-1039-1040/">花花酱 LeetCode Weekly Contest 135 (1037, 1038, 1039, 1040)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-135-1037-1038-1039-1040/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 134 (1033,1034,1035,1036)</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-134/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-134/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 28 Apr 2019 05:42:58 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5114</guid>

					<description><![CDATA[<p>1033. Moving Stones Until Consecutive Solution: Math Time complexity: O(1)Space complexity: O(1) [crayon-663cb2b3d4825191351323/] 1034. Coloring A Border Solution: DFS Time complexity: O(mn)Space complexity: O(mn) [crayon-663cb2b3d4828478862735/]&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-134/">花花酱 LeetCode Weekly Contest 134 (1033,1034,1035,1036)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2><strong>1033. Moving Stones Until Consecutive</strong></h2>



<p>Solution: Math</p>



<p>Time complexity: O(1)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 4 ms / 8.3 MB
class Solution {
public:
  vector&lt;int&gt; numMovesStones(int a, int b, int c) {
    if (a &gt; c) swap(a, c);
    if (a &gt; b) swap(a, b);
    if (b &gt; c) swap(b, c);
    int u = c - b - 1 + (b - a -1);
    int l = 0;
    if (a + 1 == b &amp;&amp; b + 1 == c) l = 0;
    else if (a + 2 &gt;= b || b + 2 &gt;= c) l = 1;
    else l = 2;
    return {l, u};
  }
};</pre>
</div></div>



<h2><strong>1034. Coloring A Border</strong><br></h2>



<p>Solution: DFS</p>



<p>Time complexity: O(mn)<br>Space complexity: O(mn)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, 52 MB / 12.6 MB
class Solution {
public:
  vector&lt;vector&lt;int&gt;&gt; colorBorder(vector&lt;vector&lt;int&gt;&gt;&amp; grid, int r0, int c0, int color) {
    vector&lt;vector&lt;int&gt;&gt; b(grid.size(), vector&lt;int&gt;(grid[0].size()));
    dfs(grid, r0, c0, grid[r0][c0], b);
    for (int i = 0; i &lt; b.size(); ++i)
      for (int j = 0; j &lt; b[0].size(); ++j)
        if (b[i][j] &gt; 0) grid[i][j] = color;
    return grid;
  }
private:
  bool dfs(const vector&lt;vector&lt;int&gt;&gt;&amp; grid, int r, int c, int color, vector&lt;vector&lt;int&gt;&gt;&amp; b) {
    if (r &lt; 0 || c &lt; 0 || r &gt;= grid.size() || c &gt;= grid[0].size()) return true;
    if (grid[r][c] != color) return true;
    if (b[r][c]) return false;
    b[r][c] = -1;
    bool valid = dfs(grid, r + 1, c, color, b) |
                 dfs(grid, r - 1, c, color, b) | 
                 dfs(grid, r, c + 1, color, b) |
                 dfs(grid, r, c - 1, color, b);
    if (valid) b[r][c] = 1;
    return false;
  }
};</pre>
</div></div>



<h2><strong>1035. Uncrossed Lines</strong><br></h2>



<p>Solution: LCS</p>



<p>Time complexity: O(nm)<br>Space complexity: O(mn)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, 12 ms / 12.1 MB
class Solution {
public:
  int maxUncrossedLines(vector&lt;int&gt;&amp; A, vector&lt;int&gt;&amp; B) {
    const int m = A.size();
    const int n = B.size();
    vector&lt;vector&lt;int&gt;&gt; dp(m + 1, vector&lt;int&gt;(n + 1));
    dp[0][0] = 0;
    for (int i = 1; i &lt;= m; ++i)
      for (int j = 1; j &lt;= n; ++j) {        
        if (A[i - 1] == B[j - 1]) 
          dp[i][j] = dp[i-1][j-1] + 1;
        else
          dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
      }
    return dp[m][n];
  }
};</pre>
</div></div>



<h2><strong>1036. Escape a Large Maze</strong></h2>



<p>Solution: limited search</p>



<p>Time complexity: O(b^2)<br>Space complexity: O(b^2)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

// Author: Huahua, running time: 168 ms, 49.7 MB
class Solution {
public:
  bool isEscapePossible(vector<vector<int>>&#038; blocked, vector<int>&#038; source, vector<int>&#038; target) {        
    for (const auto&#038; p : blocked)
      b.insert(static_cast<long>(p[0]) << 32 | p[1]);
    seen = 0;
    t = target;
    bool first = dfs(source[0], source[1]);
    t = source;
    bool second = dfs(target[0], target[1]);
    return first &#038;&#038; second;
  }
private:
  const static int kMaxN = 1000000;
  const static int kMaxSeen = 20000;
  unordered_set<long> b;
  vector<int> t;
  int seen;
  int tx;
  int ty;
  
  bool dfs(int x, int y) {
    if (x < 0 || y < 0 || x >= kMaxN || y >= kMaxN) return false;
    if (x == t[0] &#038;&#038; y == t[1]) return true;
    long key = static_cast<long>(x) << 32 | y;
    if (b.find(key) != b.end()) return false;    
    b.insert(key);
    if (++seen > kMaxSeen) return true;    
    return dfs(x + 1, y) ||
           dfs(x &#8211; 1, y) ||
           dfs(x, y + 1) ||
           dfs(x, y &#8211; 1);
  }
};
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-134/">花花酱 LeetCode Weekly Contest 134 (1033,1034,1035,1036)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-134/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 133</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-133/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-133/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 21 Apr 2019 04:39:26 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[dp]]></category>
		<category><![CDATA[trie]]></category>
		<category><![CDATA[weekly]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5092</guid>

					<description><![CDATA[<p>LeetCode 1029 Two City Scheduling Solution1: DP dp[i][j] := min cost to put j people into city A for the first i peopledp[0][0] = 0dp[i][0]&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-133/">花花酱 LeetCode Weekly Contest 133</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/3A98vh5zsqw?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/weekly-133.png" alt="" class="wp-image-5098" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/weekly-133.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/weekly-133-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/weekly-133-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<h2><strong>LeetCode 1029  Two City Scheduling</strong></h2>



<p>Solution1: DP</p>



<p>dp[i][j] := min cost to put j people into city A for the first i people<br>dp[0][0] = 0<br>dp[i][0] = dp[i -1][0] + cost_b<br>dp[i][j] = min(dp[i &#8211; 1][j] + cost_b, dp[i &#8211; 1][j &#8211; 1] + cost_a)<br>ans := dp[n][n/2]</p>



<p>Time complexity: O(n^2)<br>Space complexity: O(n^2)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 8 ms
class Solution {
public:
  int twoCitySchedCost(vector&lt;vector&lt;int&gt;&gt;&amp; costs) {
    int n = costs.size();
    vector&lt;vector&lt;int&gt;&gt; dp(n + 1, vector&lt;int&gt;(n + 1, INT_MAX / 2));
    dp[0][0] = 0;
    for (int i = 1; i &lt;= n; ++i) {      
      dp[i][0] = dp[i - 1][0] + costs[i - 1][1];
      for (int j = 1; j &lt;= i; ++j)
        dp[i][j] = min(dp[i - 1][j - 1] + costs[i - 1][0], 
                       dp[i - 1][j] + costs[i - 1][1]);
    }
    return dp[n][n / 2];
  }
};</pre>
</div></div>



<p>Solution 2: Greedy</p>



<p>Sort by cost_a &#8211; cost_b</p>



<p>Choose the first n/2 people for A, rest for B</p>



<p>Time complexity: O(nlogn)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 8 ms
class Solution {
public:
  int twoCitySchedCost(vector&lt;vector&lt;int&gt;&gt;&amp; costs) {
    int n = costs.size();
    sort(begin(costs), end(costs), [](const auto&amp; c1, const auto&amp; c2){
      return c1[0] - c1[1] &lt; c2[0] - c2[1];
    });
    int ans = 0;
    for (int i = 0; i &lt; n; ++i)
      ans += i &lt; n/2 ? costs[i][0] : costs[i][1];    
    return ans;
  }
};</pre>
</div></div>



<h2><strong> 1030.&nbsp;Matrix Cells in Distance Order</strong></h2>



<p>Solution: Sorting</p>



<p>Time complexity: O(RC*log(RC))<br>Space complexity: O(RC)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;vector&lt;int&gt;&gt; allCellsDistOrder(int R, int C, int r0, int c0) {
    vector&lt;vector&lt;int&gt;&gt; ans;
    for (int i = 0; i &lt; R; ++i)
      for (int j = 0; j &lt; C; ++j)
        ans.push_back({i, j});
    std::sort(begin(ans), end(ans), [r0, c0](const vector&lt;int&gt;&amp; a, const vector&lt;int&gt;&amp; b){
      return (abs(a[0] - r0) + abs(a[1] - c0)) &lt; (abs(b[0] - r0) + abs(b[1] - c0));
    });
    return ans;
  }
};</pre>
</div></div>



<h2><strong>1031. Maximum Sum of Two Non-Overlapping Subarrays</strong></h2>



<p>Solution: Prefix sum</p>



<p>Time complexity: O(n^2)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int maxSumTwoNoOverlap(vector&lt;int&gt;&amp; A, int L, int M) {
    const int n = A.size();
    vector&lt;int&gt; s(n + 1, 0);
    for (int i = 0; i &lt; n; ++i)
      s[i + 1] = s[i] + A[i];
    int ans = 0;
    for (int i = 0; i &lt;= n - L; ++i) {
      int ls = s[i + L] - s[i];
      int ms = max(maxSum(s, 0, i - M - 1, M), 
                   maxSum(s, i + L, n - M, M));
      ans = max(ans, ls + ms);      
    }
    return ans;
  }
private:
  int maxSum(const vector&lt;int&gt;&amp; s, int start, int end, int l) {
    int ans = INT_MIN;    
    for (int i = start; i &lt;= end; ++i)
      ans = max(ans, s[i + l] - s[i]);
    return ans;
  }
};</pre>
</div></div>



<h2><strong> 1032. Stream of Characters</strong></h2>



<p>Solution: Trie</p>



<p>Time complexity: <br></p>



<ul><li>build O(sum(len(w))</li><li>query O(max(len(w)) </li></ul>



<p>Space complexity: O(sum(len(w))</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, 320 ms, 95 MB
class TrieNode {
public:        
  ~TrieNode() {
    for (auto node : next_)
      delete node;
  }

  void reverse_build(const string&amp; s, int i) {
    if (i == -1) {
      is_word_ = true;
      return;
    }
    const int idx = s[i] - 'a';
    if (!next_[idx]) next_[idx] = new TrieNode();
    next_[idx]-&gt;reverse_build(s, i - 1);
  }
  
  bool reverse_search(const string&amp; s, int i) {
    if (i == -1 || is_word_) return is_word_;
    const int idx = s[i] - 'a';
    if (!next_[idx]) return false;
    return next_[idx]-&gt;reverse_search(s, i - 1);
  }

private:
  bool is_word_ = false;
  TrieNode* next_[26] = {0};
};

class StreamChecker {
public:
  StreamChecker(vector&lt;string&gt;&amp; words) {
    root_ = std::make_unique&lt;TrieNode&gt;();
    for (const string&amp; w : words)
      root_-&gt;reverse_build(w, w.length() - 1);
  }

  bool query(char letter) {
    s_ += letter;
    return root_-&gt;reverse_search(s_, s_.length() - 1);    
  }
  
private:
  string s_;
  unique_ptr&lt;TrieNode&gt; root_;
};</pre>

</div><h2 class="tabtitle">Java</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 133 ms
class StreamChecker {
  class TrieNode {
    public TrieNode() {
      isWord = false;
      next = new TrieNode[26];
    }
    public boolean isWord;
    public TrieNode next[];    
  }
  
  private TrieNode root;
  private StringBuilder sb;

  public StreamChecker(String[] words) {
    root = new TrieNode();
    sb = new StringBuilder();
    for (String word : words) {
      TrieNode node = root;
      char[] w = word.toCharArray();
      for (int i = w.length - 1; i &gt;= 0; --i) {        
        int idx = w[i] - 'a';
        if (node.next[idx] == null) node.next[idx] = new TrieNode();
        node = node.next[idx];
      }
      node.isWord = true;
    }
  }

  public boolean query(char letter) {
    sb.append(letter);
    TrieNode node = root;
    for (int i = sb.length() - 1; i &gt;= 0; --i) {      
      int idx = sb.charAt(i) - 'a';
      if (node.next[idx] == null) return false;
      if (node.next[idx].isWord) return true;
      node = node.next[idx];
    }
    return false;
  }  
}</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-133/">花花酱 LeetCode Weekly Contest 133</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-133/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 132 (1025,1026,1027,1028)</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-132/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-132/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 14 Apr 2019 04:12:05 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5064</guid>

					<description><![CDATA[<p>1025. Divisor Game Solution: Recursion with Memoization Time complexity: O(n^2)Space complexity: O(n) [crayon-663cb2b3d4cd2373178715/] 1026. Maximum Difference Between Node and Ancestor Solution: Resolution, pass min /&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-132/">花花酱 LeetCode Weekly Contest 132 (1025,1026,1027,1028)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/QRSDXF8ZrmE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<p><strong>1025. Divisor Game</strong></p>



<p>Solution: Recursion with Memoization</p>



<p>Time complexity: O(n^2)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 12 ms
class Solution {
public:
  bool divisorGame(int N) {
    cache_ = vector&lt;int&gt;(N + 1, -1);
    return canWin(N);
  }
private:
  vector&lt;int&gt; cache_;
  bool canWin(int N) {
    if (N == 1) return false;
    if (cache_[N] != -1) return cache_[N];
    bool win = false;
    for (int i = 1; i &lt; N; ++i)
      if (N % i == 0)
        win |= !canWin(N - i);
    return cache_[N] = win;
  }
};</pre>
</div></div>



<p><strong>1026. Maximum Difference Between Node and Ancestor</strong></p>



<p>Solution: Resolution, pass min / max of ancestor nodes</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  int maxAncestorDiff(TreeNode* root) {
    if (!root) return 0;
    return maxDiff(root, root-&amp;gt;val, root-&amp;gt;val);
  }
private:
  int maxDiff(TreeNode* root, int l, int r) {
    if (!root) return 0;
    int cur = max(abs(root-&amp;gt;val - l), abs(root-&amp;gt;val - r));
    l = min(l, root-&amp;gt;val);
    r = max(r, root-&amp;gt;val);
    return max(cur, max(maxDiff(root-&amp;gt;left, l, r),
                        maxDiff(root-&amp;gt;right, l, r)));
  }
};</pre>
</div></div>



<p><strong>1027.  Longest Arithmetic Sequence </strong></p>



<p>Solution 1: Brute Force + Pruning</p>



<p>Time complexity: O(n^3) ~ O(n^2) in practice<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 352 ms
class Solution {
public:
  int longestArithSeqLength(vector&lt;int&gt;&amp; A) {
    int n = A.size();
    unordered_set&lt;int&gt; h;
    int ans = 2;
    for (int a: A) h.insert(a);
    for (int i = 0; i &lt; n - 1; ++i)
      for (int j = i + 1; j &lt; n; ++j) {
        int d = (A[j] - A[i]);
        int t = A[j] + d;
        int l = 2;
        if (!h.count(t)) continue;
        int k = j + 1;
        for (int k = j + 1; k &lt; n; ++k)
          if (A[k] == t) {
            t += d;
            ++l;
          }        
        ans = max(ans, l);
      }
    return ans;
  }
};</pre>
</div></div>



<p><strong>1028. Recover a Tree From Preorder Traversal</strong></p>



<p>Solution: Recursion</p>



<p>Check the current depth and expected depth, if don&#8217;t match, return nullptr.</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 24 ms
class Solution {
public:
  TreeNode* recoverFromPreorder(string S) {
    int i = 0;
    return recover(S, i, 0);
  }
private:
  TreeNode* recover(const string&amp; s, int&amp; i, int depth) {    
    const int d = getD(s, i);
    if (d != depth) { i -= d; return nullptr; }    
    auto root = new TreeNode(getVal(s, i));
    root-&gt;left = recover(s, i, d + 1);    
    root-&gt;right = recover(s, i, d + 1);
    return root;
  }
  
  int getD(const string&amp; s, int&amp; i) {
    int d = 0;
    while (i &lt; s.length() &amp;&amp; s[i] == '-') {++d; ++i;}
    return d;
  }
  
  int getVal(const string&amp; s, int&amp; i) {
    int val = 0;
    while (i &lt; s.length() &amp;&amp; isdigit(s[i]))
      val = val * 10 + (s[i++] - '0');       
    return val;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-132/">花花酱 LeetCode Weekly Contest 132 (1025,1026,1027,1028)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-132/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 131 (1021, 1022, 1023, 1024)</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-131-1021-1022-1023-1024/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-131-1021-1022-1023-1024/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 07 Apr 2019 22:46:19 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[leetcode]]></category>
		<category><![CDATA[weekly]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=5015</guid>

					<description><![CDATA[<p>LeetCode 1021. Remove Outermost Parentheses Solution: Track # of opened parentheses Let n denote the # of opened parentheses after current char, keep &#8216;(&#8216; if&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-131-1021-1022-1023-1024/">花花酱 LeetCode Weekly Contest 131 (1021, 1022, 1023, 1024)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p><strong>LeetCode 1021. Remove Outermost Parentheses</strong></p>



<p>Solution: Track # of opened parentheses</p>



<p>Let n denote the # of  opened parentheses after current char, keep &#8216;(&#8216; if n &gt; 1 and keep &#8216;)&#8217; if n &gt; 0</p>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  string removeOuterParentheses(string S) {    
    string ans;
    int n = 0;    
    for (char c : S) {      
      if (c == '(' &amp;amp;&amp;amp; n++) ans += c;
      if (c == ')' &amp;amp;&amp;amp; --n) ans += c;      
    }
    return ans;
  }
};</pre>
</div></div>



<p><strong>LeetCode 1022. Sum of Root To Leaf Binary Numbers</strong></p>



<p>Solution: Recursion + Math</p>



<p>Keep tracking the number from root to current node.</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
    int sumRootToLeaf(TreeNode* root) {      
      return sums(root, 0);
    }
private:
    static constexpr int kMod = 1e9 + 7;
    int sums(TreeNode* root, int c) {
      if (!root) return 0;
      c = ((c &lt;&lt; 1) | root-&gt;val) % kMod;
      if (!root-&gt;left &amp;&amp; !root-&gt;right) {
        return c;
      }
      return sums(root-&gt;left, c) + sums(root-&gt;right, c);
    }
};</pre>
</div></div>



<p><strong>LeetCode 1023. Camelcase Matching</strong></p>



<p>Solution: String&#8230;</p>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;bool&gt; camelMatch(vector&lt;string&gt;&amp; queries, string p) {
    vector&lt;bool&gt; ans;
    for (const string&amp; q : queries)
      ans.push_back(match(q, p));
    return ans;
  }
private:
  bool match(const string&amp; q, const string&amp; p) {    
    int m = p.length();
    int n = q.length();
    int i = 0;
    int j = 0;
    for (i = 0; i &lt; n; ++i) {      
      if (j == m &amp;&amp; isupper(q[i])) return false;      
      if ((j == m || isupper(p[j])) &amp;&amp; islower(q[i])) continue;        
      if ((isupper(p[j]) || isupper(q[i])) &amp;&amp; p[j] != q[i]) return false;
      if (islower(p[j]) &amp;&amp; p[j] != q[i]) continue;
      ++j;
    }
    return i == n &amp;&amp; j == m;
  }
};</pre>
</div></div>



<p><strong>LeetCode 1024. Video Stitching</strong></p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/tdrPFN9d1y4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<p>Solution 1: DP</p>



<p>Time complexity: O(nT^2)<br>Space complexity: O(T^2)</p>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1024-ep248.png" alt="" class="wp-image-5024" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1024-ep248.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1024-ep248-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1024-ep248-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, 16 ms / 9.5 MB
class Solution {
public:
  int videoStitching(vector&lt;vector&lt;int&gt;&gt;&amp; clips, int T) {
    constexpr int kInf = 101;
    // dp[i][j] := min clips to cover range [i, j]
    vector&lt;vector&lt;int&gt;&gt; dp(T + 1, vector&lt;int&gt;(T + 1, kInf));   
    for (const auto&amp; c : clips) {
      int s = c[0];
      int e = c[1];
      for (int l = 1; l &lt;= T; ++l) {
        for (int i = 0; i &lt;= T - l; ++i) {
          int j = i + l;
          if (s &gt; j || e &lt; i) continue;
          if (s &lt;= i &amp;&amp; e &gt;= j) dp[i][j] = 1;
          else if (e &gt;= j) dp[i][j] = min(dp[i][j], dp[i][s] + 1);
          else if (s &lt;= i) dp[i][j] = min(dp[i][j], dp[e][j] + 1);
          else dp[i][j] = min(dp[i][j], dp[i][s] + 1 + dp[e][j]);          
        }
      }
    }
    return dp[0][T] == kInf ? -1 : dp[0][T];
  }
};</pre>

</div><h2 class="tabtitle">C++/V2</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua, running time: 20 ms / 9.4 MB
class Solution {
public:
  int videoStitching(vector&lt;vector&lt;int&gt;&gt;&amp; clips, int T) {
    constexpr int kInf = 101;
    // dp[i][j] := min clips to cover range [i, j]
    vector&lt;vector&lt;int&gt;&gt; dp(T + 1, vector&lt;int&gt;(T + 1));
    for (int i = 0; i &lt;= T; ++i)
      for (int j = 0; j &lt;= T; ++j)
        dp[i][j] = i &lt; j ? kInf : 0;
    for (const auto&amp; c : clips) {
      const int s = min(c[0], T);
      const int e = min(c[1], T);
      for (int l = 1; l &lt;= T; ++l)
        for (int i = 0, j = l; j &lt;= T; ++i, ++j)
          dp[i][j] = min(dp[i][j], dp[i][s] + 1 + dp[e][j]);
    }
    return dp[0][T] == kInf ? -1 : dp[0][T];
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-131-1021-1022-1023-1024/">花花酱 LeetCode Weekly Contest 131 (1021, 1022, 1023, 1024)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-131-1021-1022-1023-1024/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 130 (1017, 1018, 1019, 1020)</title>
		<link>https://zxi.mytechroad.com/blog/uncategorized/leetcode-weekly-contest-130/</link>
					<comments>https://zxi.mytechroad.com/blog/uncategorized/leetcode-weekly-contest-130/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 31 Mar 2019 04:58:31 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[weekly]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4993</guid>

					<description><![CDATA[<p>1017. Convert to Base -2 Solution: Math / Simulation Time complexity: O(logn)Space complexity: O(logn) [crayon-663cb2b3d50fc958993520/] [crayon-663cb2b3d50fe937847567/] 1018.&#160;Binary Prefix Divisible By 5 Solution: Math Time complexity:&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/uncategorized/leetcode-weekly-contest-130/">花花酱 LeetCode Weekly Contest 130 (1017, 1018, 1019, 1020)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/uo0jozNyNlg?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<h2><strong>1017. Convert to Base -2</strong></h2>



<p><strong>Solution: Math / Simulation</strong></p>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1017-ep247.png" alt="" class="wp-image-5007" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1017-ep247.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1017-ep247-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/04/1017-ep247-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<p>Time complexity: O(logn)<br>Space complexity: O(logn)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  string baseNeg2(int N) {
    if (N == 0) return &quot;0&quot;; 
    vector&lt;char&gt; ans;
    while (N) {
      ans.push_back((N &amp; 1) + '0');
      N = -(N &gt;&gt; 1);
    }    
    return {rbegin(ans), rend(ans)};
  }
};</pre>

</div><h2 class="tabtitle">base K</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:  
  string baseNeg2(int N) {   
    if (N == 0) return &quot;0&quot;; 
    return baseNegK(N, -2);
  }
private:
  string baseNegK(int N, int K) {
    vector&lt;char&gt; ans;
    while (N) {
      int r = N % K;
      N /= K;
      if (r &lt; 0) {
        r += -K;
        N += 1;
      }
      ans.push_back(r + '0');
    }    
    return {rbegin(ans), rend(ans)};
  }
};</pre>
</div></div>



<h2><strong> 1018.&nbsp;Binary Prefix Divisible By 5</strong><br></h2>



<p><strong>Solution: Math</strong></p>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;bool&gt; prefixesDivBy5(vector&lt;int&gt;&amp; A) {
    int num = 0;
    vector&lt;bool&gt; ans(A.size());    
    for (int i = 0; i &lt; A.size(); ++i) {
      num = ((num &lt;&lt; 1) | A[i]) % 5;
      ans[i] = num == 0;
    }
    return ans;
  }
};</pre>
</div></div>



<h2><strong> 1019.&nbsp;Next Greater Node In Linked List</strong><br></h2>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/e4BtnOVy0Gs?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<p><strong>Solution: Reverse + Monotonic Stack</strong></p>



<p>Process in reverse order and keep a monotonically increasing stack, pop all the elements that are smaller than the current one, then the top of the stack (if exists) will be the next greater node.</p>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/03/1030-ep246.png" alt="" class="wp-image-5002" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/03/1030-ep246.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/03/1030-ep246-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/03/1030-ep246-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<p>Time complexity: O(n)<br>Space complexity: O(n)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  vector&lt;int&gt; nextLargerNodes(ListNode* head) {    
    vector&lt;int&gt; nums;
    while (head) {
      nums.push_back(head-&gt;val);
      head = head-&gt;next;      
    }
    stack&lt;int&gt; s;
    vector&lt;int&gt; ans(nums.size());
    for (int i = nums.size() - 1; i &gt;= 0; --i) {
      while (!s.empty() &amp;&amp; s.top() &lt;= nums[i]) s.pop();
      ans[i] = s.empty() ? 0 : s.top();
      s.push(nums[i]);
    }
    return ans;
  }
};</pre>
</div></div>



<h2><strong>1020. Number of Enclaves</strong></h2>



<p><strong>Solution: DFS / Connected Components</strong></p>



<p>Time complexity: O(mn)<br>Space complexity: O(mn)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  int numEnclaves(vector&lt;vector&lt;int&gt;&gt;&amp; A) {
    int ans = 0;
    for (int i = 0; i &lt; A.size(); ++i)
      for (int j = 0; j &lt; A[0].size(); ++j) {
        int count = 0;
        if (!dfs(A, j, i, count))
          ans += count;
      }
    return ans;
  }
private:
  static constexpr int dirs[5]{0, -1, 0, 1, 0};
  bool dfs(vector&lt;vector&lt;int&gt;&gt;&amp; A, int x, int y, int&amp; count) {
    if (x &lt; 0 || x == A[0].size() || y &lt; 0 || y == A.size()) return true;    
    if (A[y][x] == 0) return false;    
    ++count;
    A[y][x] = 0;
    bool valid = false;    
    for (int i = 0; i &lt; 4; ++i)
      valid |= dfs(A, x + dirs[i], y + dirs[i + 1], count);
    return valid;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/uncategorized/leetcode-weekly-contest-130/">花花酱 LeetCode Weekly Contest 130 (1017, 1018, 1019, 1020)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/uncategorized/leetcode-weekly-contest-130/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 129 (1020, 1021, 1022, 1023)</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-129-1020-1021-1022-1023/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-129-1020-1021-1022-1023/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 24 Mar 2019 15:08:48 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4985</guid>

					<description><![CDATA[<p>1020.&#160;Partition Array Into Three Parts With Equal Sum Return true if there is a 2/3*sum prefix sum after a 1/3 prefix sum [crayon-663cb2b3d5377609694179/] Time complexity:&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-129-1020-1021-1022-1023/">花花酱 LeetCode Weekly Contest 129 (1020, 1021, 1022, 1023)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2><strong>1020.&nbsp;Partition Array Into Three Parts With Equal Sum</strong></h2>



<p>Return true if there is a 2/3*sum prefix sum after a 1/3 prefix sum</p>



<pre class="crayon-plain-tag">[---- 1/3 ----][-----1/3-----][-----1/3-----]
[------------2/3-------------][-----1/3-----]</pre>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">Python</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution:
  def canThreePartsEqualSum(self, A: List[int]) -&amp;gt; bool:
    s = sum(A)
    if s % 3 != 0: return False    
    c = 0
    found = False
    for a in A:
      c += a
      if c == s // 3 * 2 and found: return True
      if c == s // 3: found = True
    return False</pre>
</div></div>



<h2><strong>1021.&nbsp;Best Sightseeing Pair</strong></h2>



<p>Greedy, only keep the best A[i] + i so far and pair with A[j] &#8211; j, i &lt; j</p>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  int maxScoreSightseeingPair(vector&lt;int&gt;&amp; A) {
    int ans = 0;
    int left = 0;
    for (int i = 0; i &lt; A.size(); ++i) {
      ans = max(ans, left + A[i] - i);
      left = max(left, A[i] + i);
    }
    return ans;
  }
};</pre>
</div></div>



<h2><strong>1022.&nbsp;Smallest Integer Divisible by K</strong></h2>



<p>Math</p>



<p>Time complexity: O(K)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  int smallestRepunitDivByK(int K) {
    if (K % 2 == 0 || K % 5 == 0) return -1;
    int r = 0;
    for (int l = 1; l &lt;= K; ++l) {
      r = (r * 10 + 1) % K;
      if (r == 0) return l;
    }
    return -1;
  }
};</pre>
</div></div>



<h2><strong>1023.&nbsp;Binary String With Substrings Representing 1 To N</strong></h2>



<p>Brute Force, try all possible substrings and convert them into decimals.</p>



<p>Time complexity: O(|S|*log(N)^2)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">Python</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution:
  def queryString(self, S: str, N: int) -&amp;gt; bool:
    s = set()
    c = 0    
    for l in range(1, 32):
      for i in range(0, len(S) - l + 1):        
        n = int(S[i:i+l], 2)
        if n == 0 or n &gt; N or n in s: continue        
        s.add(n)
        c += 1
    return c == N</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-129-1020-1021-1022-1023/">花花酱 LeetCode Weekly Contest 129 (1020, 1021, 1022, 1023)</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-129-1020-1021-1022-1023/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly 125</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-125/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-125/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 24 Feb 2019 20:56:09 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4903</guid>

					<description><![CDATA[<p>Problems https://zxi.mytechroad.com/blog/graph/leetcode-997-find-the-town-judge/ https://zxi.mytechroad.com/blog/tree/leetcode-998-maximum-binary-tree-ii/ https://zxi.mytechroad.com/blog/simulation/leetcode-999-available-captures-for-rook/ https://zxi.mytechroad.com/blog/hashtable/leetcode-1001-grid-illumination/</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-125/">花花酱 LeetCode Weekly 125</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><iframe width="500" height="375" src="https://www.youtube.com/embed/ACBdojAxPSc?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>


<h2>Problems</h2>



<ul><li><a href="https://zxi.mytechroad.com/blog/graph/leetcode-997-find-the-town-judge/">https://zxi.mytechroad.com/blog/graph/leetcode-997-find-the-town-judge/</a></li><li><a href="https://zxi.mytechroad.com/blog/tree/leetcode-998-maximum-binary-tree-ii/">https://zxi.mytechroad.com/blog/tree/leetcode-998-maximum-binary-tree-ii/</a></li><li><a href="https://zxi.mytechroad.com/blog/simulation/leetcode-999-available-captures-for-rook/">https://zxi.mytechroad.com/blog/simulation/leetcode-999-available-captures-for-rook/</a></li><li><a href="https://zxi.mytechroad.com/blog/hashtable/leetcode-1001-grid-illumination/">https://zxi.mytechroad.com/blog/hashtable/leetcode-1001-grid-illumination/</a></li></ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-125/">花花酱 LeetCode Weekly 125</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-125/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>LeetCode Weekly Contest 124</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-124/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-124/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 17 Feb 2019 19:43:57 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4879</guid>

					<description><![CDATA[<p>Solutions https://zxi.mytechroad.com/blog/tree/leetcode-993-cousins-in-binary-tree/ https://zxi.mytechroad.com/blog/searching/leetcode-994-rotting-oranges/ https://zxi.mytechroad.com/blog/greedy/leetcode-995-minimum-number-of-k-consecutive-bit-flips/ https://zxi.mytechroad.com/blog/searching/leetcode-996-number-of-squareful-arrays/</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-124/">LeetCode Weekly Contest 124</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/ISnktonx7rY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-124.png" alt="" class="wp-image-4881" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-124.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-124-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-124-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<h2><strong>Solutions</strong></h2>



<ul><li><a href="https://zxi.mytechroad.com/blog/tree/leetcode-993-cousins-in-binary-tree/">https://zxi.mytechroad.com/blog/tree/leetcode-993-cousins-in-binary-tree/</a></li><li><a href="https://zxi.mytechroad.com/blog/searching/leetcode-994-rotting-oranges/">https://zxi.mytechroad.com/blog/searching/leetcode-994-rotting-oranges/</a></li><li><a href="https://zxi.mytechroad.com/blog/greedy/leetcode-995-minimum-number-of-k-consecutive-bit-flips/">https://zxi.mytechroad.com/blog/greedy/leetcode-995-minimum-number-of-k-consecutive-bit-flips/</a></li><li><a href="https://zxi.mytechroad.com/blog/searching/leetcode-996-number-of-squareful-arrays/">https://zxi.mytechroad.com/blog/searching/leetcode-996-number-of-squareful-arrays/</a></li></ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-124/">LeetCode Weekly Contest 124</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-124/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly 123</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-123/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-123/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Mon, 11 Feb 2019 04:28:00 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4840</guid>

					<description><![CDATA[<p>Solutions https://zxi.mytechroad.com/blog/simulation/leetcode-989-add-to-array-form-of-integer/ https://zxi.mytechroad.com/blog/graph/leetcode-990-satisfiability-of-equality-equations/ https://zxi.mytechroad.com/blog/greedy/leetcode-991-broken-calculator/ https://zxi.mytechroad.com/blog/two-pointers/leetcode-992-subarrays-with-k-different-integers/</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-123/">花花酱 LeetCode Weekly 123</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/FZPtxuxArLU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<h2><strong>Solutions</strong></h2>



<ul><li><a href="https://zxi.mytechroad.com/blog/simulation/leetcode-989-add-to-array-form-of-integer/">https://zxi.mytechroad.com/blog/simulation/leetcode-989-add-to-array-form-of-integer/</a></li><li><a href="https://zxi.mytechroad.com/blog/graph/leetcode-990-satisfiability-of-equality-equations/">https://zxi.mytechroad.com/blog/graph/leetcode-990-satisfiability-of-equality-equations/</a></li><li><a href="https://zxi.mytechroad.com/blog/greedy/leetcode-991-broken-calculator/">https://zxi.mytechroad.com/blog/greedy/leetcode-991-broken-calculator/</a></li><li><a href="https://zxi.mytechroad.com/blog/two-pointers/leetcode-992-subarrays-with-k-different-integers/">https://zxi.mytechroad.com/blog/two-pointers/leetcode-992-subarrays-with-k-different-integers/</a></li></ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-123/">花花酱 LeetCode Weekly 123</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-123/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 122</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-122/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-122/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 03 Feb 2019 08:46:43 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4784</guid>

					<description><![CDATA[<p>https://zxi.mytechroad.com/blog/simulation/leetcode-985-sum-of-even-numbers-after-queries/ https://zxi.mytechroad.com/blog/geometry/leetcode-986-interval-list-intersections/ https://zxi.mytechroad.com/blog/tree/leetcode-987-vertical-order-traversal-of-a-binary-tree/ https://zxi.mytechroad.com/blog/tree/leetcode-988-smallest-string-starting-from-leaf/</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-122/">花花酱 LeetCode Weekly Contest 122</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/5xL_N2S3-QU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-122.png" alt="" class="wp-image-4785" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-122.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-122-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/02/weekly-122-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<ul><li><a href="https://zxi.mytechroad.com/blog/simulation/leetcode-985-sum-of-even-numbers-after-queries/">https://zxi.mytechroad.com/blog/simulation/leetcode-985-sum-of-even-numbers-after-queries/</a></li><li><a href="https://zxi.mytechroad.com/blog/geometry/leetcode-986-interval-list-intersections/">https://zxi.mytechroad.com/blog/geometry/leetcode-986-interval-list-intersections/</a></li><li><a href="https://zxi.mytechroad.com/blog/tree/leetcode-987-vertical-order-traversal-of-a-binary-tree/">https://zxi.mytechroad.com/blog/tree/leetcode-987-vertical-order-traversal-of-a-binary-tree/</a></li><li><a href="https://zxi.mytechroad.com/blog/tree/leetcode-988-smallest-string-starting-from-leaf/">https://zxi.mytechroad.com/blog/tree/leetcode-988-smallest-string-starting-from-leaf/</a></li></ul>



<p></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-122/">花花酱 LeetCode Weekly Contest 122</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-122/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>花花酱 LeetCode Weekly Contest 121</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-121/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-121/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 27 Jan 2019 18:39:19 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[weekly]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4706</guid>

					<description><![CDATA[<p>https://zxi.mytechroad.com/blog/greedy/leetcode-984-string-without-aaa-or-bbb/ https://zxi.mytechroad.com/blog/bit/leetcode-982-triples-with-bitwise-and-equal-to-zero/ https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-983-minimum-cost-for-tickets/ https://zxi.mytechroad.com/blog/hashtable/leetcode-981-time-based-key-value-store/</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-121/">花花酱 LeetCode Weekly Contest 121</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe width="500" height="375" src="https://www.youtube.com/embed/wByfMK9vL6M?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div></figure>



<figure class="wp-block-image"><img width="960" height="540" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/01/Weekly-121.png" alt="" class="wp-image-4707" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2019/01/Weekly-121.png 960w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/01/Weekly-121-300x169.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2019/01/Weekly-121-768x432.png 768w" sizes="(max-width: 960px) 100vw, 960px" /></figure>



<ul><li><a href="https://zxi.mytechroad.com/blog/greedy/leetcode-984-string-without-aaa-or-bbb/">https://zxi.mytechroad.com/blog/greedy/leetcode-984-string-without-aaa-or-bbb/</a></li><li><a href="https://zxi.mytechroad.com/blog/bit/leetcode-982-triples-with-bitwise-and-equal-to-zero/">https://zxi.mytechroad.com/blog/bit/leetcode-982-triples-with-bitwise-and-equal-to-zero/</a></li><li><a href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-983-minimum-cost-for-tickets/">https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-983-minimum-cost-for-tickets/</a></li><li><a href="https://zxi.mytechroad.com/blog/hashtable/leetcode-981-time-based-key-value-store/">https://zxi.mytechroad.com/blog/hashtable/leetcode-981-time-based-key-value-store/</a></li></ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-121/">花花酱 LeetCode Weekly Contest 121</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-121/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>LeetCode Weekly Contest 113</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 02 Dec 2018 03:47:20 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<category><![CDATA[rank]]></category>
		<category><![CDATA[weekly contest]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=4389</guid>

					<description><![CDATA[<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/">LeetCode Weekly Contest 113</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img class="alignnone size-large wp-image-4390" src="https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-1024x627.png" alt="" width="1024" height="627" srcset="https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-1024x627.png 1024w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-300x184.png 300w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest-768x470.png 768w, https://zxi.mytechroad.com/blog/wp-content/uploads/2018/12/contest.png 1435w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/">LeetCode Weekly Contest 113</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-113/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>LeetCode Weekly Contest 94</title>
		<link>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-94/</link>
					<comments>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-94/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 22 Jul 2018 11:18:57 +0000</pubDate>
				<category><![CDATA[Leetcode]]></category>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=3268</guid>

					<description><![CDATA[<p>花花酱 LeetCode 872. Leaf-Similar Trees [Easy] [Tree] 花花酱 LeetCode 874. Walking Robot Simulation [Easy Medium] [Simulation] [HashTable] 花花酱 LeetCode 875. Koko Eating Bananas [Medium Easy] [Binary Search] 花花酱&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-94/">LeetCode Weekly Contest 94</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<ul>
<li><a href="http://zxi.mytechroad.com/blog/tree/leetcode-872-leaf-similar-trees/">花花酱 LeetCode 872. Leaf-Similar Trees</a> [Easy] [Tree]</li>
<li><a href="http://zxi.mytechroad.com/blog/simulation/leetcode-874-walking-robot-simulation/">花花酱 LeetCode 874. Walking Robot Simulation</a> [<del>Easy</del> Medium] [Simulation] [HashTable]</li>
<li><a href="http://zxi.mytechroad.com/blog/algorithms/binary-search/leetcode-875-koko-eating-bananas/">花花酱 LeetCode 875. Koko Eating Bananas</a> [<del>Medium</del> Easy] [Binary Search]</li>
<li><a href="http://zxi.mytechroad.com/blog/dynamic-programming/leetcode-873-length-of-longest-fibonacci-subsequence/">花花酱 LeetCode 873. Length of Longest Fibonacci Subsequence</a> [Medium] [DP] [HashTable] [Binary Search]</li>
</ul>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-94/">LeetCode Weekly Contest 94</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/leetcode/leetcode-weekly-contest-94/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
