JavaScript Solution using some Math


  • 0
    N
    var optimalDivision = function(nums) {
        var result = nums[0] + '';
        var len = nums.length;
        
        if(len === 1) {
           return result;       
        } else {
            for(var i = 1; i < len; i++) {
                if(i === 1 && len > 2) {
                    result += '/(' +  nums[i];                  
                } else {
                    result += '/' +  nums[i]; 
                }
            }
        }
        
        return (len > 2) ? result += ')' : result;
        
    };
    

Log in to reply
 

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