← 返回 amazon 的题目列表K-th Smallest Element in Two Sorted Arrays
类型:online_judge
Given two integer arrays nums1 and nums2, each sorted in non-decreasing order, and an integer k, return the k-th smallest element in the sorted order of their union. k is 1-indexed.
Requirements:
Do not explicitly merge the two arrays.
Either array may be empty, and the arrays may have different lengths.
Values may be duplicated or negative.
It is guaranteed that 1 <= k <= len(nums1) + len(nums2).
Target time complexity: O(log(min(m, n))), where m and n are the array lengths.
Input Format
Line 1: elements of nums1, separated by spaces. An empty line represents an empty array.
Line 2: elements of nums2, separated by spaces. An empty line represents an empty array.
Line 3: integer k.
Example 1
Input:
1 3 5
2 4 6
4
Output:
4
Example 2
Input:
1 2 2
2 3
4
Output:
2
Constraints
0 <= m, n <= 10^5
m + n >= 1
Values are in [-10^9, 10^9].
Example
Input
1 3 5
2 4 6
4
Output
4