<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	
	>
<channel>
	<title>
	Comments on: 花花酱 LeetCode 64. Minimum Path Sum	</title>
	<atom:link href="https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-64-minimum-path-sum/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-64-minimum-path-sum/</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jul 2018 19:28:12 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>
	<item>
		<title>
		By: David Huang		</title>
		<link>https://zxi.mytechroad.com/blog/dynamic-programming/leetcode-64-minimum-path-sum/#comment-22</link>

		<dc:creator><![CDATA[David Huang]]></dc:creator>
		<pubDate>Sun, 22 Jul 2018 19:28:12 +0000</pubDate>
		<guid isPermaLink="false">http://zxi.mytechroad.com/blog/?p=982#comment-22</guid>

					<description><![CDATA[Nice codes and explanation, Thank you Huahua.

Changes for solution 1
a)change the order of x and y. (Don&#039;t know why you switch them:)) 
b) Remove unused arguments  m and n.

The following codes were accepted too.

class Solution {
public:
    int minPathSum(vector&#060;vector&#062;&#038; grid) {
        int m = grid.size();
        if (m == 0) return 0;
        int n = grid[0].size();
        
        s_ = vector&#060;vector&#062;(m, vector(n, 0));
        
        return minPathSum(grid, m - 1, n - 1);
    }    
private:
    long minPathSum(const vector&#060;vector&#062;&#038; grid, 
                   int x, int y) {        
        if (x == 0 &#038;&#038; y == 0) return grid[y][x];
        if (x &#060; 0 &#124;&#124; y  0) return s_[x][y];
        
        int ans = grid[x][y] + min(minPathSum(grid, x - 1, y),
                                   minPathSum(grid, x, y - 1));
        return s_[x][y] = ans;
    }
    
    vector&#060;vector&#062; s_;
};]]></description>
			<content:encoded><![CDATA[<p>Nice codes and explanation, Thank you Huahua.</p>
<p>Changes for solution 1<br />
a)change the order of x and y. (Don&#8217;t know why you switch them:))<br />
b) Remove unused arguments  m and n.</p>
<p>The following codes were accepted too.</p>
<p>class Solution {<br />
public:<br />
    int minPathSum(vector&lt;vector&gt;&amp; grid) {<br />
        int m = grid.size();<br />
        if (m == 0) return 0;<br />
        int n = grid[0].size();</p>
<p>        s_ = vector&lt;vector&gt;(m, vector(n, 0));</p>
<p>        return minPathSum(grid, m &#8211; 1, n &#8211; 1);<br />
    }<br />
private:<br />
    long minPathSum(const vector&lt;vector&gt;&amp; grid,<br />
                   int x, int y) {<br />
        if (x == 0 &amp;&amp; y == 0) return grid[y][x];<br />
        if (x &lt; 0 || y  0) return s_[x][y];</p>
<p>        int ans = grid[x][y] + min(minPathSum(grid, x &#8211; 1, y),<br />
                                   minPathSum(grid, x, y &#8211; 1));<br />
        return s_[x][y] = ans;<br />
    }</p>
<p>    vector&lt;vector&gt; s_;<br />
};</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
