We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b2c04ff commit e537f56Copy full SHA for e537f56
problems/0062.不同路径.md
@@ -243,7 +243,37 @@ public:
243
244
245
Java:
246
+```java
247
+ /**
248
+ * 1. 确定dp数组下表含义 dp[i][j] 到每一个坐标可能的路径种类
249
+ * 2. 递推公式 dp[i][j] = dp[i-1][j] dp[i][j-1]
250
+ * 3. 初始化 dp[i][0]=1 dp[0][i]=1 初始化横竖就可
251
+ * 4. 遍历顺序 一行一行遍历
252
+ * 5. 推导结果 。。。。。。。。
253
+ *
254
+ * @param m
255
+ * @param n
256
+ * @return
257
+ */
258
+ public static int uniquePaths(int m, int n) {
259
+ int[][] dp = new int[m][n];
260
+ //初始化
261
+ for (int i = 0; i < m; i++) {
262
+ dp[i][0] = 1;
263
+ }
264
+ for (int i = 0; i < n; i++) {
265
+ dp[0][i] = 1;
266
267
268
+ for (int i = 1; i < m; i++) {
269
+ for (int j = 1; j < n; j++) {
270
+ dp[i][j] = dp[i-1][j]+dp[i][j-1];
271
272
273
+ return dp[m-1][n-1];
274
275
+
276
+```
277
278
Python:
279
0 commit comments