Share my 21ms java solution with comments
To find the maximum ,we can enumerate how digits we should get from nums1 , we suppose it is i.\n\nSo ,  the digits from nums2 is K - i.\n\nAnd we can use a sta
To find the maximum ,we can enumerate how digits we should get from nums1 , we suppose it is i.\n\nSo ,  the digits from nums2 is K - i.\n\nAnd we can use a stack to get the get maximum number(x digits) from one array.\n\nOK, Once we choose two maximum subarray , we should combine it to the answer.\n\nIt is just like merger sort, but we should pay attention to the case: the two digital are equal.\n\nwe should find the digits behind it to judge which digital we should choose now.\n\nIn other words,we should judge which subarry is bigger than the other.\n\nThat's all.\n\nIf you have any question or suggest, I am happy you can comment on my blog : [Create Maximum Number][1].\n\nThanks, merry christmas :)\n\n *update:use stack to find max sub array and it runs 21ms now.( thanks to @dietpepsi )*\n\n   \n\n     /**  * Created by hrwhisper on 2015/11/23.  * http://www.hrwhisper.me/leetcode-create-maximum-number/  */\n    \n    \n    public class Solution {\n        public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n            int get_from_nums1 = Math.min(nums1.length, k);\n            int[] ans = new int[k];\n            for (int i = Math.max(k - nums2.length, 0); i <= get_from_nums1; i++) {\n                int[] res1 = new int[i];\n                int[] res2 = new int[k - i];\n                int[] res = new int[k];\n                res1 = solve(nums1, i);\n                res2 = solve(nums2, k - i);\n                int pos1 = 0, pos2 = 0, tpos = 0;\n                \n                while (res1.length > 0 && res2.length > 0 && pos1 < res1.length && pos2 < res2.length) {\n                    if (compare(res1, pos1, res2, pos2))\n                        res[tpos++] = res1[pos1++];\n                    else\n                        res[tpos++] = res2[pos2++];\n                }\n                while (pos1 < res1.length)\n                    res[tpos++] = res1[pos1++];\n                while (pos2 < res2.length)\n                    res[tpos++] = res2[pos2++];\n    \n                if (!compare(ans, 0, res, 0))\n                    ans = res;\n            }\n    \n            return ans;\n        }\n    \n        public boolean compare(int[] nums1, int start1, int[] nums2, int start2) {\n            for (; start1 < nums1.length && start2 < nums2.length; start1++, start2++) {\n                if (nums1[start1] > nums2[start2]) return true;\n                if (nums1[start1] < nums2[start2]) return false;\n            }\n            return start1 != nums1.length;\n        }\n    \n        public int[] solve(int[] nums, int k) {\n            int[] res = new int[k];\n            int len = 0;\n            for (int i = 0; i < nums.length; i++) {\n                while (len > 0 && len + nums.length - i > k && res[len - 1] < nums[i]) {\n                    len--;\n                }\n                if (len < k)\n                    res[len++] = nums[i];\n            }\n            return res;\n        } }\n\n\n  [1]: http://www.hrwhisper.me/leetcode-create-maximum-number/
['Java']