1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/两个有序数组的第 K 小乘积 [kth-smallest-product-of-two-sorted-arrays].html
2022-03-29 12:43:11 +08:00

49 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

给你两个 <strong>从小到大排好序</strong>&nbsp;且下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>nums1</code>&nbsp;<code>nums2</code>&nbsp;以及一个整数&nbsp;<code>k</code>&nbsp;,请你返回第<em>&nbsp;</em><code>k</code>&nbsp;(从 <strong>1</strong>&nbsp;开始编号)小的&nbsp;<code>nums1[i] * nums2[j]</code><em>&nbsp;</em>的乘积,其中<em>&nbsp;</em><code>0 &lt;= i &lt; nums1.length</code><em> </em><em> </em><code>0 &lt;= j &lt; nums2.length</code>&nbsp;
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums1 = [2,5], nums2 = [3,4], k = 2
<b>输出:</b>8
<b>解释:</b>第 2 小的乘积计算如下:
- nums1[0] * nums2[0] = 2 * 3 = 6
- nums1[0] * nums2[1] = 2 * 4 = 8
第 2 小的乘积为 8 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums1 = [-4,-2,0,3], nums2 = [2,4], k = 6
<b>输出:</b>0
<strong>解释:</strong>第 6 小的乘积计算如下:
- nums1[0] * nums2[1] = (-4) * 4 = -16
- nums1[0] * nums2[0] = (-4) * 2 = -8
- nums1[1] * nums2[1] = (-2) * 4 = -8
- nums1[1] * nums2[0] = (-2) * 2 = -4
- nums1[2] * nums2[0] = 0 * 2 = 0
- nums1[2] * nums2[1] = 0 * 4 = 0
第 6 小的乘积为 0 。
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums1 = [-2,-1,0,1,2], nums2 = [-3,-1,2,4,5], k = 3
<b>输出:</b>-6
<b>解释:</b>第 3 小的乘积计算如下:
- nums1[0] * nums2[4] = (-2) * 5 = -10
- nums1[0] * nums2[3] = (-2) * 4 = -8
- nums1[4] * nums2[0] = 2 * (-3) = -6
第 3 小的乘积为 -6 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums1.length, nums2.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>-10<sup>5</sup> &lt;= nums1[i], nums2[j] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= k &lt;= nums1.length * nums2.length</code></li>
<li><code>nums1</code>&nbsp;<code>nums2</code>&nbsp;都是从小到大排好序的。</li>
</ul>