Median中位数
Description
Given a unsorted array with integers, find the median of it.
A median is the middle number of the array after it is sorted.
If there are even numbers in the array, return the N/2-th number after sorted.
public class Solution {
/**
* @param nums: A list of integers
* @return: An integer denotes the middle number of the array
*/
public int median(int[] nums) {
// write your code here
Arrays.sort(nums) ;
int len = nums.length ;
if(len % 2 == 0){
return nums[len / 2 - 1] ;
}else{
return nums[(len-1) / 2] ;
}
}
}