Skip to content

Commit 5ace0fc

Browse files
add skeleton for 980
1 parent c88fc4e commit 5ace0fc

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ _If you like this project, please leave me a star._ ★
141141
|987|[Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_987.java) | |Medium| Recursion
142142
|986|[Interval List Intersections](https://leetcode.com/problems/interval-list-intersections/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_986.java) | |Medium| Two Pointers
143143
|985|[Sum of Even Numbers After Queries](https://leetcode.com/problems/sum-of-even-numbers-after-queries/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_985.java) | |Easy| Array
144+
|980|[Unique Paths III](https://leetcode.com/problems/unique-paths-iii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_980.java) | |Hard| Backtracking, DFS
144145
|979|[Distribute Coins in Binary Tree](https://leetcode.com/problems/distribute-coins-in-binary-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_979.java) | |Medium| Recursion
145146
|977|[Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_977.java) | |Easy| Array
146147
|976|[Largest Perimeter Triangle](https://leetcode.com/problems/largest-perimeter-triangle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_976.java) | |Easy| Math Array
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 980. Unique Paths III
5+
*
6+
* On a 2-dimensional grid, there are 4 types of squares:
7+
* 1 represents the starting square. There is exactly one starting square.
8+
* 2 represents the ending square. There is exactly one ending square.
9+
* 0 represents empty squares we can walk over.
10+
* -1 represents obstacles that we cannot walk over.
11+
* Return the number of 4-directional walks from the starting square to the ending square, that walk over every non-obstacle square exactly once.
12+
*
13+
* Example 1:
14+
* Input: [[1,0,0,0],[0,0,0,0],[0,0,2,-1]]
15+
* Output: 2
16+
* Explanation: We have the following two paths:
17+
* 1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2)
18+
* 2. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2)
19+
*
20+
* Example 2:
21+
* Input: [[1,0,0,0],[0,0,0,0],[0,0,0,2]]
22+
* Output: 4
23+
* Explanation: We have the following four paths:
24+
* 1. (0,0),(0,1),(0,2),(0,3),(1,3),(1,2),(1,1),(1,0),(2,0),(2,1),(2,2),(2,3)
25+
* 2. (0,0),(0,1),(1,1),(1,0),(2,0),(2,1),(2,2),(1,2),(0,2),(0,3),(1,3),(2,3)
26+
* 3. (0,0),(1,0),(2,0),(2,1),(2,2),(1,2),(1,1),(0,1),(0,2),(0,3),(1,3),(2,3)
27+
* 4. (0,0),(1,0),(2,0),(2,1),(1,1),(0,1),(0,2),(0,3),(1,3),(1,2),(2,2),(2,3)
28+
*
29+
* Example 3:
30+
* Input: [[0,1],[2,0]]
31+
* Output: 0
32+
* Explanation:
33+
* There is no path that walks over every empty square exactly once.
34+
* Note that the starting and ending square can be anywhere in the grid.
35+
*
36+
* Note:
37+
* 1 <= grid.length * grid[0].length <= 20
38+
* */
39+
public class _980 {
40+
public static class Solution1 {
41+
public int uniquePathsIII(int[][] grid) {
42+
//TODO: implement it
43+
return -1;
44+
}
45+
}
46+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._980;
4+
import org.junit.BeforeClass;
5+
import org.junit.Ignore;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
@Ignore
11+
public class _980Test {
12+
private static _980.Solution1 solution1;
13+
private static int[][] grid;
14+
15+
@BeforeClass
16+
public static void setup() {
17+
solution1 = new _980.Solution1();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
grid = new int[][]{
23+
{1, 0, 0, 0},
24+
{0, 0, 0, 0},
25+
{0, 0, 2, -1},
26+
};
27+
assertEquals(2, solution1.uniquePathsIII(grid));
28+
}
29+
30+
}

0 commit comments

Comments
 (0)