Median of Two Sorted Arrays

This commit is contained in:
2022-03-21 19:30:38 +08:00
parent 29138c91a3
commit 35c715ebb1
3 changed files with 91 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#ifndef S0004_MEDIAN_OF_TWO_SORTED_ARRAYS
#define S0004_MEDIAN_OF_TWO_SORTED_ARRAYS
#include <vector>
class Solution {
public:
/**
* @brief Median of Two Sorted Arrays
*
* Given two sorted arrays `nums1` and `nums2` of size `m` and `n`
* respectively, return the median of the two sorted arrays.
*
* The overall run time complexity should be `O(log(m+n))`.
*
* @param nums1 the first sorted array
* @param nums2 the second sorted array
* @return the median of the two sorted arrays
*/
double findMedianSortedArrays(std::vector<int>& nums1,
std::vector<int>& nums2);
int getKthElement(const std::vector<int>& nums1,
const std::vector<int>& nums2, int k);
};
#endif