题解 | #多数组中位数#
多数组中位数
https://www.nowcoder.com/practice/b6bb0bce88894108bfc23e9b7b012420
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param arr1 int整型一维数组 * @param arr1Len int arr1数组长度 * @param arr2 int整型一维数组 * @param arr2Len int arr2数组长度 * @return int整型 */ int getUpMedian(int* arr1, int arr1Len, int* arr2, int arr2Len ) { // write code here int medianCount = (arr1Len + arr2Len + 1) / 2; int i = 0, j = 0; long median = 0; while (medianCount > 0) { if ((i < arr1Len) && (arr1[i] <= arr2[j])) { median = arr1[i++]; } else { median = arr2[j++]; } medianCount--; } return median; }