Unique Paths II
בינוני
שאלה מראיונות עבודה ממאגר שאלות של LeetCode שאלה מספר 63 נשאל ב: Microsoft
Now consider obstacles on the grid; determine the number of unique paths from top-left to bottom-right, avoiding obstacles.
פתרון קוד
JavaScript
Python
function uniquePathsWithObstacles(grid) {
const rows = grid.length;
const cols = grid[0].length;
const dp = new Array(cols).fill(0);
dp[0] = grid[0][0] === 0 ? 1 : 0;
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
if (grid[r][c] === 1) {
dp[c] = 0;
} else if (c > 0) {
dp[c] += dp[c - 1];
}
}
}
return dp[cols - 1];
}הסבר וידאו כיצד לפתור את השאלה

לעבור את ראיון העבודה הבא שלך בהצלחה
קורס דיגיטלי מקיף עם +25 שיעורים מעשיים, כשעתיים של וידאו, וליווי של מראיין בכיר.