Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 579 Bytes

1891. Cutting Ribbons.md

File metadata and controls

25 lines (19 loc) · 579 Bytes

1891. Cutting Ribbons

https://leetcode.com/problems/cutting-ribbons/

solution

class Solution:
    def maxLength(self, ribbons: List[int], k: int) -> int:
        left = 0
        right = max(ribbons)

        while left < right:
            mid = (left + right + 1) // 2
            count = sum(ribbon // mid for ribbon in ribbons)
            if count >= k:
                left = mid
            else:
                right = mid - 1

        return left

时间复杂度:O()
空间复杂度:O()