use std::collections::VecDeque; struct Solution; impl Solution { pub fn max_number(a: Vec, b: Vec, k: i32) -> Vec { let k = k as usize; let mut i = 0; let n = a.len(); let mut j = 0; let m = b.len(); let mut st1 = Vec::new(); let mut st2 = Vec::new(); let mut cnt = 0; while ib[j] || j+1==m || i+1!=n && a[i+1]>b[j+1]) { while let Some(t) = st1.last() { if cnt-1+n+m-i-j st2[j] { res.push(st1[i]); i += 1; } else if st1[i] < st2[j] { res.push(st2[j]); j += 1; } else { if i + 1 == st1.len() { res.push(st2[j]); j += 1; } else if j + 1 == st2.len() { res.push(st1[i]); i += 1; } else if st1[i+1]>st2[j+1] { res.push(st1[i]); i += 1; } else { res.push(st2[j]); j += 1; } } } } res } } fn main() { let nums1 = vec![3,9]; let nums2 = vec![8,9]; let k = 3; let res = Solution::max_number(nums1,nums2, k); for x in res { print!("{x} "); } }