forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fbdf39f
commit 696377d
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(D) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
|
||
add_executable(D main.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/// Source : https://leetcode.com/problems/path-with-maximum-minimum-value/ | ||
/// Author : liuyubobobo | ||
/// Time : 2019-06-30 | ||
|
||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
|
||
/// Binary Search | ||
/// Time Complexity: O(log(max(A)) * m * n) | ||
/// Space Complexity: O(1) | ||
class Solution { | ||
|
||
private: | ||
int m, n; | ||
|
||
public: | ||
int maximumMinimumPath(vector<vector<int>>& A) { | ||
|
||
m = A.size(), n = A[0].size(); | ||
|
||
int min_value = A[0][0], max_value = A[0][0]; | ||
for(int i = 0; i < m; i ++) | ||
for(int j = 0; j < n; j ++) | ||
min_value = min(min_value, A[i][j]), | ||
max_value = max(max_value, A[i][j]); | ||
|
||
int l = min_value, r = max_value; | ||
while(l < r){ | ||
int mid = l + (r - l + 1) / 2; | ||
if(ok(A, mid)) l = mid; | ||
else r = mid - 1; | ||
} | ||
return l; | ||
} | ||
|
||
private: | ||
bool ok(const vector<vector<int>>& A, int K){ | ||
|
||
if(A[0][0] < K || A[m - 1][n - 1] < K) return false; | ||
|
||
const int d[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; | ||
queue<int> q; | ||
q.push(0); | ||
|
||
vector<bool> visited(m * n, false); | ||
visited[0] = true; | ||
|
||
while(!q.empty()){ | ||
int cx = q.front() / n, cy = q.front() % n; | ||
q.pop(); | ||
|
||
for(int i = 0; i < 4; i ++){ | ||
int nx = cx + d[i][0], ny = cy + d[i][1]; | ||
int index = nx * n + ny; | ||
if(nx >= 0 && nx < m && ny >= 0 && ny < n && A[nx][ny] >= K && !visited[index]){ | ||
visited[index] = true; | ||
q.push(index); | ||
} | ||
} | ||
} | ||
return visited.back(); | ||
} | ||
}; | ||
|
||
|
||
int main() { | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -751,7 +751,7 @@ email: [[email protected]](mailto:[email protected]) | |
| 1099 | [Two Sum Less Than K](https://leetcode.com/problems/two-sum-less-than-k/) | [无] | [C++](1099-Two-Sum-Less-Than-K/cpp-1099/) | | | | ||
| 1100 | [Find K-Length Substrings With No Repeated Characters](https://leetcode.com/problems/find-k-length-substrings-with-no-repeated-characters/) | [无] | [C++](1100-Find-K-Length-Substrings-With-No-Repeated-Characters/cpp-1100/) | | | | ||
| 1101 | [The Earliest Moment When Everyone Become Friends](https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends/) | [无] | [C++](1101-The-Earliest-Moment-When-Everyone-Become-Friends/cpp-1101/) | | | | ||
| | | | | | | | ||
| 1102 | [Path With Maximum Minimum Value](https://leetcode.com/problems/path-with-maximum-minimum-value/) | [无]<br/>[缺:并查集] | [C++](1102-Path-With-Maximum-Minimum-Value/cpp-1102/) | | | | ||
| 1103 | [Distribute Candies to People](https://leetcode.com/problems/distribute-candies-to-people/) | [solution](https://leetcode.com/problems/distribute-candies-to-people/solution/) | [C++](1103-Distribute-Candies-to-People/cpp-1103/) | | | | ||
| 1104 | [Path In Zigzag Labelled Binary Tree](https://leetcode.com/problems/path-in-zigzag-labelled-binary-tree/) | [无] | [C++](1104-Path-In-Zigzag-Labelled-Binary-Tree/cpp-1104/) | | | | ||
| 1105 | [Filling Bookcase Shelves](https://leetcode.com/problems/filling-bookcase-shelves/) | [无] | [C++](1105-Filling-Bookcase-Shelves/cpp-1105/) | | | | ||
|