Leetcode 553 Solution
This article provides solution to leetcode question 553 (optimal-division)
Access this page by simply typing in "lcs 553" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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:]])
)