File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int uniquePaths (int m , int n ) {
3+ /**
4+ * ์ฌ๊ธฐ์ ์ด๋๊ฐ๋ฅํ ๊ฒฝ์ฐ๋ right, down ๋๊ฐ์ง ๊ฒฝ์ฐ์ด๋ค.
5+ * ๋ชจ๋ ๋ธ๋ก์ ๋ด ์ผ์ชฝ ๋ธ๋ก์์ ๋๋ก ์จ ๊ฒฝ์ฐ, ๋ด ์ ๋ธ๋ก์์ ๋๋ก ์จ ๊ฒฝ์ฐ๋ฅผ ๊ณ ๋ คํด์ [i-1][j] + [i][j-1]๋ก ํํํ ์ ์๋ค.
6+ * ๋จ ๊ฐ๋ก ์ฒซ๋ฒ์งธ ์ค๊ณผ ์ธ๋ก ์ฒซ๋ฒ์งธ ์ค์ 1๋ก ์ด๊ธฐํ ํด์ค์ผ ํ๋ค. (์๋ํ๋ฉด ๊ฐ๊ฐ down, right์ด ์๊ธฐ ๋๋ฌธ์ ๊ทธ ๋ธ๋ก๋ค์ 1๊ฐ์ง ๊ฒฝ์ฐ๋ก๋ฐ์ ๋๋ฌํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.)
7+ */
8+ int [][] dp = new int [m ][n ];
9+ for (int i = 0 ; i < m ; i ++) {
10+ dp [i ][0 ] = 1 ;
11+ }
12+
13+ for (int j = 0 ; j < n ; j ++) {
14+ dp [0 ][j ] = 1 ;
15+ }
16+
17+ for (int i = 1 ; i < m ; i ++) {
18+ for (int j = 1 ; j < n ; j ++) {
19+ dp [i ][j ] = dp [i -1 ][j ] + dp [i ][j -1 ];
20+ }
21+ }
22+ return dp [m - 1 ][n - 1 ];
23+ }
24+ }
You canโt perform that action at this time.
0 commit comments