题解 | #三个牛群中位数#
三个牛群中位数
https://www.nowcoder.com/practice/8bc0369faf7c4ac5ab336f38e859db05
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param herd1 int整型vector * @param herd2 int整型vector * @param herd3 int整型vector * @return double浮点型 */ double findMedianSortedArray(vector<int>& herd1, vector<int>& herd2, vector<int>& herd3) { // write code here for(auto t_2:herd2) herd1.emplace_back(t_2); for(auto t_3:herd3) herd1.emplace_back(t_3); sort(herd1.begin(), herd1.end()); int len = herd1.size(); if(len%2==0) return ((double)herd1[len/2-1] + (double)herd1[len/2])/2.0; return (double)herd1[len/2]; } };
虚数五行区解题中心 文章被收录于专栏
非淡泊无以明志,非宁静无以致远