Skip to content

Commit b6ac400

Browse files
add 1102
1 parent 474e2d4 commit b6ac400

File tree

4 files changed

+116
-0
lines changed

4 files changed

+116
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -433,5 +433,7 @@ LeetCode
433433
|1096|[Brace Expansion II](https://leetcode.com/problems/brace-expansion-ii/) | c | [c++](./src/1096-Brace-Expansion-II/1096.cpp) |[python](./src/1096-Brace-Expansion-II/1096.py)|[go](./src/1096-Brace-Expansion-II/1096.go)||Hard|
434434
|1099|[Two Sum Less Than K](https://leetcode.com/contest/biweekly-contest-3/problems/two-sum-less-than-k/) | c | [c++](./src/1099-Two-Sum-Less-Than-K/1099.cpp) |[python](./src/1099-Two-Sum-Less-Than-K/1099.py)|[go](./src/1099-Two-Sum-Less-Than-K/1099.go)||Easy|
435435
|1100|[Find K-Length Substrings With No Repeated Characters](https://leetcode.com/contest/biweekly-contest-3/problems/find-k-length-substrings-with-no-repeated-characters/) | c | [c++](./src/1100-Find-K-Length-Substrings-With-No-Repeated-Characters/1100.cpp) |[python](./src/1100-Find-K-Length-Substrings-With-No-Repeated-Characters/1100.py)|[go](./src/1100-Find-K-Length-Substrings-With-No-Repeated-Characters/1100.go)||Easy|
436+
|1102|[Path With Maximum Minimum Value](https://leetcode.com/contest/biweekly-contest-3/problems/path-with-maximum-minimum-value/) | c | [c++](./src/1102-Path-With-Maximum-Minimum-Value/1102.cpp) |[python](./src/1102-Path-With-Maximum-Minimum-Value/1102.py)|[go](./src/1102-Path-With-Maximum-Minimum-Value/1102.go)||Medium|
436437
|1103|[Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people/) | c | [c++](./src/1103-Distribute-Candies-to-People/1103.cpp) |[python](./src/1103-Distribute-Candies-to-People/1103.py)|[go](./src/1103-Distribute-Candies-to-People/1103.go)||Easy|
438+
|1104|[Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/) | c | [c++](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.cpp) |[python](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.py)|[go](./src/1104-Path-In-Zigzag-Labelled-Binary-Tree/1104.go)||Easy|
437439
|1105|[Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/) | c | [c++](./src/1105-Filling-Bookcase-Shelves/1105.cpp) |[python](./src/1105-Filling-Bookcase-Shelves/1105.py)|[go](./src/1105-Filling-Bookcase-Shelves/1105.go)||Medium|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution
2+
{
3+
public:
4+
int maximumMinimumPath(vector<vector<int>>& A)
5+
{
6+
int r = A.size(), c = A[0].size();
7+
vector<vector<int>> vi(r, vector<int>(c, 0));
8+
priority_queue<vector<int>> q;
9+
q.push({A[0][0], 0, 0});
10+
while (!q.empty())
11+
{
12+
auto it = q.top(); q.pop();
13+
if (it[1] == r-1 and it[2] == c-1) return it[0];
14+
for (auto& d : dire)
15+
{
16+
int nx = d[0] + it[1], ny = d[1] + it[2];
17+
if (nx >= 0 and nx < r and ny >= 0 and ny < c
18+
and vi[nx][ny] == 0)
19+
{
20+
vi[nx][ny] = 1;
21+
q.push({min(it[0], A[nx][ny]), nx, ny});
22+
}
23+
}
24+
}
25+
return 0;
26+
}
27+
private:
28+
int dire[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import "container/heap"
2+
func min(a, b int) int {
3+
if a < b {
4+
return a
5+
}
6+
return b
7+
}
8+
9+
type Item struct {
10+
pre, x, y int
11+
}
12+
13+
type Heap []*Item
14+
15+
func (h Heap) Len() int {
16+
return len(h)
17+
}
18+
19+
func (h Heap) Less(i, j int) bool {
20+
return h[i].pre > h[j].pre
21+
}
22+
23+
func (h Heap) Swap(i, j int) {
24+
h[i], h[j] = h[j], h[i]
25+
}
26+
27+
func (h *Heap) Pop() interface{} {
28+
old := *h
29+
n := len(old)
30+
item := old[n - 1]
31+
*h = old[0:n - 1]
32+
return item
33+
}
34+
35+
func (h *Heap) Push(x interface{}) {
36+
*h = append(*h, x.(*Item))
37+
}
38+
39+
func maximumMinimumPath(A [][]int) int {
40+
r, c := len(A), len(A[0])
41+
dire := [4][2]int{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}
42+
vi := make([][]int, r)
43+
for i := 0; i < r; i++ {
44+
vi[i] = make([]int, c)
45+
}
46+
vi[0][0] = 1
47+
48+
q := &Heap{&Item{A[0][0], 0, 0}}
49+
heap.Init(q)
50+
for q.Len() > 0 {
51+
it := heap.Pop(q).(*Item)
52+
if it.x == r-1 && it.y == c-1 {
53+
return it.pre
54+
}
55+
for _, v := range dire {
56+
nx, ny := it.x + v[0], it.y + v[1]
57+
if nx >= 0 && nx < r && ny >= 0 && ny < c && vi[nx][ny] == 0 {
58+
vi[nx][ny] = 1
59+
heap.Push(q, &Item{min(it.pre, A[nx][ny]), nx, ny})
60+
}
61+
}
62+
}
63+
return 0
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import heapq
2+
class Solution:
3+
def maximumMinimumPath(self, A: List[List[int]]) -> int:
4+
dire = [[1, 0], [-1, 0], [0, 1], [0, -1]]
5+
r, c = len(A), len(A[0])
6+
vi = {(0, 0)}
7+
q = [[-A[0][0], 0, 0]]
8+
heapq.heapify(q)
9+
10+
while q:
11+
pre, x, y = heapq.heappop(q)
12+
if x == r-1 and y == c-1:
13+
return -pre
14+
15+
for i, j in dire:
16+
nx, ny = i + x, j + y
17+
if nx >= 0 and nx < r and ny >= 0 and ny < c and (nx, ny) not in vi:
18+
vi.add((nx, ny))
19+
heapq.heappush(q, [max(pre, -A[nx][ny]), nx, ny])
20+
21+
return 0

0 commit comments

Comments
 (0)