c# o(n)


  • 0
    N

    we need max result and x1/(x2/x3/.../xn) = x1/x2 * (x3...xn).
    so we could jump to the solution.

    public class Solution {
        public string OptimalDivision(int[] nums) {
            if(nums.Length <3) return string.Join("/", nums);
            var arr = new int[nums.Length-1];
            for(var i=1;i<nums.Length;i++){
                arr[i-1] = nums[i];
            }
            return string.Format("{0}/({1})",nums[0].ToString(),string.Join("/", arr));
        }
    }
    

Log in to reply
 

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