dynamic-programming: rename loop variable in UniquePaths.oneRow (WordPress reads [c] as a shortcode in the article)
This commit is contained in:
@@ -31,12 +31,12 @@ public final class UniquePaths {
|
|||||||
return table(rows, cols)[rows - 1][cols - 1];
|
return table(rows, cols)[rows - 1][cols - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** One row: row[c] already holds the cell above, row[c-1] is the cell to the left. */
|
/** One row: row[col] already holds the cell above, row[col-1] is the cell to the left. */
|
||||||
public static long oneRow(int rows, int cols) {
|
public static long oneRow(int rows, int cols) {
|
||||||
long[] row = new long[cols];
|
long[] row = new long[cols];
|
||||||
java.util.Arrays.fill(row, 1);
|
java.util.Arrays.fill(row, 1);
|
||||||
for (int r = 1; r < rows; r++) {
|
for (int r = 1; r < rows; r++) {
|
||||||
for (int c = 1; c < cols; c++) row[c] += row[c - 1];
|
for (int col = 1; col < cols; col++) row[col] += row[col - 1];
|
||||||
}
|
}
|
||||||
return row[cols - 1];
|
return row[cols - 1];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user