@@ -18,15 +18,17 @@ def shipWithinDays(self, weights, D):
1818 if daily_weight : d += 1
1919
2020 if d > D :
21- #K cannot be the answer.
22- #next round we don't need to put K in l~r.
21+ #c cannot be the answer.
22+ #next round we don't need to put c in l~r.
2323 l = c + 1
2424 else :
25- #K might ot might not be the answer.
26- #next round we still need to put K in l~r.
25+ #c might ot might not be the answer.
26+ #next round we still need to put c in l~r.
2727 r = c
2828 return l
2929
30+
31+
3032"""
3133This is a binary search problem.
3234If you do not understand binary search yet, please study it first.
@@ -43,6 +45,12 @@ def shipWithinDays(self, weights, D):
4345[2]
4446So the boundary of our answer, `l` and `r`, will collides together (`l==r`) and jump out of the loop.
4547
46- Time complexity: `O(NlogN)`. There will be `O(LogN)` iteration. For every iteration we need O(N) to calculate the `t`. `N` is the length of `piles`.
47- Space complexity is O(N). For calculating `t`.
48+ Time complexity: `O(NlogW)`.
49+ `N` is the number of `weights`.
50+ `W` is the max weight.
51+ There will be `O(LogW)` iteration. For every iteration we need O(N) to calculate the `d`.
52+ Space complexity is O(1).
53+
54+ Also take a look at problem, 875, very similar.
55+ https://leetcode.com/problems/koko-eating-bananas/discuss/750699/
4856"""
0 commit comments