2605. 从两个数字数组里生成最小数字bahttps://leetcode.cn/problems/form-smallest-number-from-two-digit-arrays/
| 2023-9-5
0  |  阅读时长 0 分钟
Date
Sep 5, 2023
need_review
need_review
type
undo
undo
难度
简单
给你两个只包含 1 到 9 之间数字的数组nums1nums2,每个数组中的元素互不相同,请你返回最小的数字,两个数组都至少包含这个数字的某个数位。
示例 1:
示例 2:
提示:
  • 1 <= nums1.length, nums2.length <= 9
  • 1 <= nums1[i], nums2[i] <= 9
  • 每个数组中,元素 互不相同 。

解法1
  • 有相同数字优先用相同数字
  • 分别找最小值, 两个最小值对比小的放左边
时间复杂度, 空间复杂度
notion image
 
解法2
使用哈希表
时间复杂度, 空间复杂度. 是两个数组中数值的范围.
notion image
  • Giscus
目录