leetcode-题5-Median of Two Sorted Arrays
通用解法:
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int a[5] = { 1,2,3,4,5 }; int b[5] = { 2,4,5,6,7 }; vector<int>res(a, a + 5); for (auto i : b) res.push_back(i); sort(res.begin(), res.end()); int mid = res.size() / 2; cout << res[mid]; system("pause"); return 0; }