Leetcode 553 Solution

This article provides solution to leetcode question 553 (optimal-division)

https://leetcode.com/problems/optimal-division

Solution

class Solution:
    def optimalDivision(self, nums: List[int]) -> str:
        if len(nums) == 1:
            return str(nums[0])
        elif len(nums) == 2:
            return "{}/{}".format(nums[0], nums[1])

        return "{}/({})".format(
            nums[0],
            "/".join([str(num) for num in nums[1:]])
        )