leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 1a59eeed000853873f72a66783c005caf3508552 |
parent | b5bc795531b91aee6dd5d6e6652aa4f8efccdeeb |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Wed, 26 Jul 2023 18:28:13 +0200 |
Daily Problem
Diffstat:A | Problems/1870.cpp | | | +++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/1870.cpp b/Problems/1870.cpp
@@ -0,0 +1,19 @@
class Solution {
public:
int minSpeedOnTime(vector<int>& dist, double hour) {
int low = 1, high = 10000000;
int res = -1;
while(low <= high) {
int mid = low + (high - low) / 2;
double time = 0;
for(int i=0; i<dist.size() - 1; i++)
time+=ceil((double)dist[i] / mid);
time += (double)dist.back() / mid;
if(time <= hour) {
res = mid;
high = mid - 1;
} else low = mid + 1;
}
return res;
}
};
diff --git a/README.md b/README.md
@@ -535,6 +535,7 @@ for solving problems.
| 1833 | Medium | [Maximum Ice Cream Bars](Problems/1833.cpp) |
| 1834 | Medium | [Single-Threaded CPU](Problems/1834.cpp) |
| 1857 | Hard | [Largest Color Value in a Directed Graph](Problems/1857.cpp) |
| 1870 | Medium | [Minimum Speed to Arrive on Time](Problems/1870.cpp) |
| 1926 | Medium | [Nearest Exit from Entrance in Maze](Problems/1926.cpp) |
| 1962 | Medium | [Remove Stones to Minimize the Total](Problems/1962.cpp) |
| 1964 | Hard | [Find the Longest Valid Obstacle Course at Each Position](Problems/1964.cpp) |