Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 40382dd

Browse files
author
Victor
authored
simplified a little.
1 parent bca733d commit 40382dd

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

‎62. Unique Paths.c

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,21 @@ Note: m and n will be at most 100.
1616
*/
1717

1818
int uniquePaths(int m, int n) {
19-
int path[100][100];
20-
int i, j;
21-
i = 0;
22-
23-
if (!m || !n) return 0;
24-
25-
while (i < m) {
26-
j = 0;
27-
while (j < n) {
28-
if (i == 0 && j == 0) {
29-
path[i][j] = 1;
30-
} else if (i == 0 || j == 0) {
31-
path[i][j] = 1;
32-
} else {
33-
path[i][j] = path[i][j - 1] + path[i - 1][j];
34-
}
35-
j ++;
36-
}
37-
i ++;
38-
}
39-
return path[m - 1][n - 1];
19+
int path[100][100];
20+
int i, j;
21+
22+
if (!m || !n) return 0;
23+
24+
for (i = 0; i < m; i ++) {
25+
for (j = 0; j < n; j ++) {
26+
if (i == 0 || j == 0) {
27+
path[i][j] = 1;
28+
} else {
29+
path[i][j] = path[i][j - 1] + path[i - 1][j];
30+
}
31+
}
32+
}
33+
return path[m - 1][n - 1];
4034
}
4135

4236

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /