https://leetcode.com/problems/optimal-division/description/
string optimalDivision(vector<int>& nums) {
if(nums.size()==0) return "";
if(nums.size()==1) return to_string(nums[0]);
string res = to_string(nums[0]);
if(nums.size()==2) return res+"/"+to_string(nums[1]);
res += "/(";
for(int i=1; i<nums.size(); i++) {
res += to_string(nums[i]) + "/";
}
res[res.size()-1] = ')';
return res;
}
No comments:
Post a Comment