4097. Minimum Value of Merged Integers
DifficultyEasy
Description
You are given an integer array nums of even length n.
You have to merge the elements of nums in pairs by merging nums[0] with nums[1], nums[2] with nums[3], and so on, until nums[n - 2] with nums[n - 1].
Return the minimum value among all the resulting merged integers.
To merge two integers, concatenate all the decimal digits of the first integer followed by all the decimal digits of the second integer.
Example 1:
Input: nums = [23,55,42,21]
Output: 2355
Explanation:
- Merging
nums[0] = 23andnums[1] = 55gives 2355. - Merging
nums[2] = 42andnums[3] = 21gives 4221. - The minimum value among the merged numbers is
min(2355, 4221) = 2355.
Example 2:
Input: nums = [34,7,11,11]
Output: 347
Explanation:
- Merging
nums[0] = 34andnums[1] = 7gives 347. - Merging
nums[2] = 11andnums[3] = 11gives 1111. - The minimum value among the merged numbers is
min(347, 1111) = 347.
Example 3:
Input: nums = [9,20]
Output: 920
Explanation:
- Merging
nums[0] = 9andnums[1] = 20gives 920. - There is only one merged number, so the minimum value is 920.
Constraints:
2 <= n == nums.length <= 100nis even1 <= nums[i] <= 1000
Solutions
Solution 1
1 | |
1 | |
1 | |
1 | |