public class Solution {
    public string OptimalDivision(int[] nums) {
        if (nums.Length == 0)
            {
                return "";
            }
            else if (nums.Length == 1)
            {
                return nums[0].ToString();
            }
            else if (nums.Length == 2)
            {
                return nums[0] + "/" + nums[1];
            }
            else
            {
                var first = nums[0];
                var dv = nums[1];
                StringBuilder sb = new StringBuilder(first + "/(");
                for (int i = 1; i < nums.Length; i++)
                {
                    sb.Append(nums[i]);
                    sb.Append("/");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append(")");

                return sb.ToString();
            }
    }
}

https://leetcode.com/problems/optimal-division/#/description

posted on 2017-05-02 17:54  Sempron2800+  阅读(151)  评论(0编辑  收藏  举报