classSolution:defshipWithinDays(self,weights: List[int],D:int) ->int: left, right =max(weights),sum(weights)defavailable(num,limit): count, current =0,0for item in weights:if current + item < num: current += itemelif current + item == num: count +=1 current =0else: count +=1 current = item count +=1if current >0else0return count <= limitwhile left <= right: mid = (left + right) //2ifavailable(mid, D): right = mid -1else: left = mid +1return left