leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0553.cpp (436B)


      1 class Solution {
      2   public:
      3     string optimalDivision(const vector<int> &nums) {
      4         const int n = nums.size();
      5         if (n == 1) return to_string(nums[0]);
      6         if (n == 2) return to_string(nums[0]) + "/" + to_string(nums[1]);
      7         string res = to_string(nums[0]) + "/(" + to_string(nums[1]);
      8         for (int i = 2; i < n; i++)
      9             res += "/" + to_string(nums[i]);
     10         res += ')';
     11         return res;
     12     }
     13 };