{"id":2091,"date":"2016-07-30T12:07:36","date_gmt":"2016-07-30T04:07:36","guid":{"rendered":"http:\/\/boweihe.me\/?p=2091"},"modified":"2016-07-30T12:07:36","modified_gmt":"2016-07-30T04:07:36","slug":"leetcode-62-unique-paths","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=2091","title":{"rendered":"LeetCode 62. Unique Paths"},"content":{"rendered":"<p>\u539f\u9898\uff1a<a href=\"https:\/\/leetcode.com\/problems\/unique-paths\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/leetcode.com\/problems\/unique-paths\/<\/a><br \/>\nrobot is located at the top-left corner of a <i>m<\/i> x <i>n<\/i> grid (marked &#8216;Start&#8217; in the diagram below).<br \/>\nThe robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked &#8216;Finish&#8217; in the diagram below).<br \/>\nHow many possible unique paths are there?<br \/>\n<img decoding=\"async\" src=\"http:\/\/leetcode.com\/wp-content\/uploads\/2014\/12\/robot_maze.png\" \/><br \/>\nAbove is a 3 x 7 grid. How many possible unique paths are there?<br \/>\n<b>Note:<\/b> <i>m<\/i> and <i>n<\/i> will be at most 100.<\/p>\n<h3>\u601d\u8def<\/h3>\n<p>\u8fd9\u662f\u4e2a\u7ecf\u5178\u7684\u9898\u76ee\uff0c\u53cd\u6b63\u5c31\u662f\u52a8\u6001\u89c4\u5212\u7684\u601d\u8def\uff1f\u8bf4\u662f\u52a8\u6001\u89c4\u5212\uff0c\u5176\u5b9e\u5c31\u662f\u4e0b\u4e00\u4e2a\u72b6\u6001\u600e\u4e48\u6765\u7684\u95ee\u9898\u3002\u6b64\u5904\u7684\u4e0b\u4e00\u72b6\u6001\u5c31\u662f\u4e00\u4e2a\u683c\u5b50solution[m][n]\u4ed6\u7684\u7ed3\u679c\u662f\u600e\u4e48\u6765\u7684\u95ee\u9898\uff0c\u7531\u4e8e\u9650\u5b9a\u53ea\u80fd\u5f80\u53f3\u6216\u8005\u5f80\u4e0b\u8d70\uff0c\u6240\u4ee5\u8fd9\u4e2a\u683c\u5b50\u7684\u8d70\u6cd5\u65e0\u975e\u662f \u4ece(m,n-1)\u548c(m-1,n)\u8d70\u8fc7\u6765\u4e24\u79cd\uff0c\u53ea\u8981\u628a\u8fd9\u4e24\u4e2a\u72b6\u6001\u7684\u7ed3\u679c\u76f8\u52a0\u5c31\u662f\u5f53\u524d\u603b\u7684\u8d70\u6cd5\u4e86\u3002<\/p>\n<h3>\u89e3\u6cd5<\/h3>\n<p>\u590d\u6742\u5ea6\u5e94\u8be5\u662fO(m*n)\uff0c\u505a\u7684\u65f6\u5019\u5728\u5de6\u4fa7\u548c\u4e0a\u4fa7\u52a0\u4e86\u4e2a0\u8fb9\u4fbf\u4e8e\u8ba1\u7b97<\/p>\n<pre class=\"lang:java decode:true \">public class Solution {\n    public int uniquePaths(int m, int n) {\n        int solutions[][] = new int[m+1][n+1];\n        solutions[1][1]=1;\n        for(int i=1; i&lt;=m; i++){\n            for(int j=1; j&lt;=n; j++){\n                if(i==1 &amp;&amp; j==1)\n                    continue;\n                solutions[i][j] = solutions[i][j-1] + solutions[i-1][j];    \/\/ Comes from left, or upper side\n            }\n        }\n        return solutions[m][n];\n    }\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u9898\uff1ahttps:\/\/leetcode.com\/problems\/unique-paths\/ robot is located at the top-left corner of a m x n grid (marked &#8216;Start&#8217; in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked &#8216;Finish&#8217; in the diagram below). How many possible [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[65,141],"class_list":["post-2091","post","type-post","status-publish","format-standard","hentry","category-technical","tag-leetcode","tag-141"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2091"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2091\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}