class Solution {
  public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param weightsA int整型vector
     * @param weightsB int整型vector
     * @return double浮点型
     */
    double findMedianSortedArrays(vector<int>& weightsA, vector<int>& weightsB) {
        // write code here
        vector<int>ve;
        int la = weightsA.size();
        int lb = weightsB.size();
        int laa = 0, lbb = 0;
        while (laa < la && lbb < lb) {
            if (weightsA[laa] < weightsB[lbb]) {
                ve.push_back(weightsA[laa]);
                laa++;
            } else {
                ve.push_back(weightsB[lbb]);
                lbb++;
            }
        }
        while (laa < la)
            ve.push_back(weightsA[laa]), laa++;
        while (lbb < lb)
            ve.push_back(weightsB[lbb]), lbb++;
        int n = ve.size();
     //   cout<<n<<endl;
        if (n % 2 == 1) {
            return ve[n / 2];
        } else
            return (ve[n / 2] + ve[n / 2 - 1]) / 2;
    }
};

一、题目考察的知识点

归并排序

二、题目解答方法的文字分析

用的是归并排序的思想,先把两个数组放进一个数组里面,然后求取中间值

三、本题解析所用的编程语言

c++