Very straight-forward solution yet still efficient in C++
If you prefer performance than anything else then check this post. The following solution is simplified for simplicity and readability, so the performance is re
If you prefer performance than anything else then check this [post](https://leetcode.com/discuss/101043/efficient-solution-accepted-best-beating-16ms-well-commented). The following solution is simplified for simplicity and readability, so the performance is reduced.\n\n    class Solution \n    {\n    public:\n        //select the maximal number in certain length within one vector;\n        vector<int> maxVector(vector<int> nums, int k) \n        {\n            while (nums.size() > k) \n            {\n                int i = 0, n = nums.size();\n                for (; i < n - 1; ++i)  //at least erase one element each time;\n                {\n                    if (nums[i] < nums[i + 1]) \n                    {\n                        nums.erase(nums.begin() + i);\n                        break;\n                    }\n                }\n                if (i == n - 1) nums.erase(nums.begin() + i);\n            }\n            return nums;\n        }\n    \n        //compare two vectors from certain index adopting lexical order;\n        //if the first vector is bigger return true otherwise return false;\n        bool compare(vector<int> &nums1, int i, vector<int> &nums2, int j) \n        {\n            while (i<nums1.size() && j<nums2.size() && nums1[i]==nums2[j]) ++i, ++j;\n            if (i<nums1.size() && j<nums2.size()) return nums1[i]>nums2[j];\n            else if(j == nums2.size()) return true;\n            else return false;\n        }\n    \n        //get the first k numbers which form the largest lexical sequence;\n        vector<int> merge(vector<int> &nums1, vector<int> &nums2, int k) \n        {\n            vector<int> res(k, 0);\n            for (int i=0, j=0, r=0; r < k; ++r) \n                res[r] = compare(nums1, i, nums2, j) ? nums1[i++] : nums2[j++];\n            return res;\n        }\n    \n        //AC - 386ms - the most intuitive solution;\n        vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) \n        {\n            int len1=nums1.size(), len2=nums2.size();\n            vector<int> v(k, 0);\n            for (int l1 = max(0, k-len2); l1 <= min(k, len1); ++l1) \n            {\n                auto v1 = maxVector(nums1, l1);\n                auto v2 = maxVector(nums2, k-l1);\n                auto tmp = merge(v1, v2, k);\n                if (compare(tmp, 0, v, 0)) v = tmp;\n            }\n            return v;\n        }\n    };
['C++']