@@ -18,15 +18,17 @@ def shipWithinDays(self, weights, D):
18
18
if daily_weight : d += 1
19
19
20
20
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.
23
23
l = c + 1
24
24
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.
27
27
r = c
28
28
return l
29
29
30
+
31
+
30
32
"""
31
33
This is a binary search problem.
32
34
If you do not understand binary search yet, please study it first.
@@ -43,6 +45,12 @@ def shipWithinDays(self, weights, D):
43
45
[2]
44
46
So the boundary of our answer, `l` and `r`, will collides together (`l==r`) and jump out of the loop.
45
47
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/
48
56
"""
0 commit comments