3-line solution with O(n)


  • 0
    K

    The minimum occurs when placing no parentheses. Conversely, the maximum occurs when the first elements is divided by the rest without parentheses, if there are more than two elements.

    class Solution(object):
            if len(nums)<=2:
                return '/'.join(str(x) for x in nums)            
            return str(nums[0])+"/("+ '/'.join(str(x) for x in nums[1:])+")"
            
                
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.