Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 425279a

Browse files
solves unique paths
1 parent 3c06bda commit 425279a

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
| 58 | [Length of Last Word](https://leetcode.com/problems/length-of-last-word) | [![Java](assets/java.png)](src/LengthOfLastWord.java) [![Python](assets/python.png)](python/length_of_last_word.py) | |
6060
| 59 | [Spiral Matrix II](https://leetcode.com/problems/spiral-matrix-ii) | [![Java](assets/java.png)](src/SpiralMatrixII.java) | |
6161
| 61 | [Rotate List](https://leetcode.com/problems/rotate-list) | [![Java](assets/java.png)](src/RotateList.java) | |
62+
| 62 | [Unique Paths](https://leetcode.com/problems/unique-paths) | [![Java](assets/java.png)](src/UniquePaths.java) | |
6263
| 66 | [Plus One](https://leetcode.com/problems/plus-one) | [![Java](assets/java.png)](src/PlusOne.java) [![Python](assets/python.png)](python/plus_one.py) | |
6364
| 67 | [Add Binary](https://leetcode.com/problems/add-binary) | [![Java](assets/java.png)](src/AddBinary.java) [![Python](assets/python.png)](python/add_binary.py) | |
6465
| 69 | [Sqrt(x)](https://leetcode.com/problems/sqrtx) | [![Java](assets/java.png)](src/Sqrtx.java) [![Python](assets/python.png)](python/sqrt.py) | |

‎src/UniquePaths.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://leetcode.com/problems/unique-paths
2+
// T: O(min(m, n))
3+
// S: O(1)
4+
5+
public class UniquePaths {
6+
public int uniquePaths(int m, int n) {
7+
final int M = Math.max(m, n) - 1, N = Math.min(m, n) - 1;
8+
long result = 1;
9+
for (int i = M + 1, j = 1 ; i <= M + N ; i++, j++) {
10+
result *= i;
11+
result /= j;
12+
}
13+
return (int) result;
14+
}
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /