Simple Java Solution


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

  • 0

    Did not think solution would be this simple. liked it!


Log in to reply
 

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