Skip to content

Commit b664c6c

Browse files
authored
week 7
1 parent c901528 commit b664c6c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

unique-paths/yeonguchoe.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int combination(int n, int r) {
4+
int k = n - r > r ? r : n - r;
5+
unsigned long long result = 1;
6+
for (int i = 0; i < k; i++) {
7+
result = result * (n - i) / (i + 1);
8+
}
9+
return result;
10+
}
11+
int uniquePaths(int m, int n) { return combination(m - 1 + n - 1, m - 1); }
12+
// 시간 복잡도: O(min(m,n))
13+
// 공간 복잡도: O(1)
14+
};

0 commit comments

Comments
 (0)