forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmlwls96.kt
More file actions
23 lines (22 loc) ยท 687 Bytes
/
gmlwls96.kt
File metadata and controls
23 lines (22 loc) ยท 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
// ์๊ฐ : O(m*n) ๊ณต๊ฐ : O(m*n)
// dp ์๊ณ ๋ฆฌ์ฆ. pathMap[y][x]๋ก ์ฌ์ ์๋ ๊ฒฝ๋ก์ ์๋
// ์์ชฝ(pathMap[y - 1][x]) + ์ผ์ชฝ( pathMap[y][x - 1]) ๊ฒฝ๋ก์ ์์ ํฉ์ด๋ค.
fun uniquePaths(m: Int, n: Int): Int {
val pathMap = Array(m) { y ->
IntArray(n) { x ->
if (y == 0 || x == 0) {
1
} else {
0
}
}
}
for (y in 1 until m) {
for (x in 1 until n) {
pathMap[y][x] = pathMap[y - 1][x] + pathMap[y][x - 1]
}
}
return pathMap[m - 1][n - 1]
}
}