/**
  * @param nums1 an integer array of length m with digits 0-9
  * @param nums2 an integer array of length n with digits 0-9
  * @param k an integer and k <= m + n
  * @return an integer array
  */
 vector maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {
     // Write your code here
     int len1 = nums1.size(), len2 = nums2.size();
     vector results;
     for (int k1 = max(k - len2, 0); k1 <= min(k, len1); ++k1)
         results = max(results, maxNumber(maxNumber(nums1, k1), maxNumber(nums2, k - k1)));
     return results;
 }
Exemplo n.º 2
0
 vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {
     int n1 = nums1.size(), n2 = nums2.size();
     vector<int> res;
     for (int k1 = max(k - n2, 0); k1 <= min(k, n1); ++k1)
     {
         res = max(res, maxNumber(maxNumber(nums1, k1), maxNumber(nums2, k - k1)));
     }
     return res;
 }
Exemplo n.º 3
0
 vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {
     vector<int> result;
     for (int i = 0; i <= k; i++) {
         if (i > nums1.size() || k-i > nums2.size())
             continue;
         vector<int> num = merge(maxNumber(nums1, i), maxNumber(nums2, k-i));
         if (result.empty() || compare(result, num) < 0) {
             result = num;
         }
     }
     return result;
 }