中位数                 var n = parseInt(read_line())                 var arr = read_line().split(' ')                 arr = arr.map(e=>parseInt(e))                 arr.sort(up)                 function up (a,b){ // 排序                     return a-b                 }                 var sum = 0                 if(n%2===0){ // 取中位数                     sum = (arr[n/2] + arr[n/2-1])/2                     print(sum)                 } else {                     print(arr[(n-1)/2])                 }
点赞 2

相关推荐

点赞 评论 收藏
分享
牛客网
牛客企业服务