321. Create Maximum Number Hard

@problem@discussion
#Stack#Greedy#Monotonic Stack



1/**
2 * [321] Create Maximum Number
3 *
4 * You are given two integer arrays nums1 and nums2 of lengths m and n respectively. nums1 and nums2 represent the digits of two numbers. You are also given an integer k.
5 * Create the maximum number of length k <= m + n from digits of the two numbers. The relative order of the digits from the same array must be preserved.
6 * Return an array of the k digits representing the answer.
7 *  
8 * Example 1:
9 * 
10 * Input: nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5
11 * Output: [9,8,6,5,3]
12 * 
13 * Example 2:
14 * 
15 * Input: nums1 = [6,7], nums2 = [6,0,4], k = 5
16 * Output: [6,7,6,0,4]
17 * 
18 * Example 3:
19 * 
20 * Input: nums1 = [3,9], nums2 = [8,9], k = 3
21 * Output: [9,8,9]
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	m == nums1.length
27 * 	n == nums2.length
28 * 	1 <= m, n <= 500
29 * 	0 <= nums1[i], nums2[i] <= 9
30 * 	1 <= k <= m + n
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/create-maximum-number/
36// discuss: https://leetcode.com/problems/create-maximum-number/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn max_number(nums1: Vec<i32>, nums2: Vec<i32>, k: i32) -> Vec<i32> {
42        vec![]
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_321() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.