my easy solution in java


  • 1
    Y
    public class Solution {
        public String optimalDivision(int[] nums) {
            if (nums.length == 1)
                return String.valueOf(nums[0]);
            if (nums.length == 2)
                return nums[0] + "/" + nums[1];
            String res = nums[0] + "/" + "(";
            for (int i = 1; i < nums.length - 1; i++)
                res += nums[i] + "/";
            return res + nums[nums.length - 1] + ")";
        }
    }

Log in to reply
 

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