Optimal Division

Problem Id: 553 Difficulty: Medium


Intuition

Solution


class Solution:
    def optimalDivision(self, nums: List[int]) -> str:
        if len(nums) == 1:
            return str(nums[0])
        elif len(nums) == 2:
            return "%d/%d" % (nums[0], nums[1])
        else:
            return "%d/(%s)" % (nums[0], '/'.join([str(i) for i in nums[1:]]))