当前位置:网站首页>Find the median of two positive arrays
Find the median of two positive arrays
2022-07-03 18:49:00 【Pear encounter】
Given two sizes, they are m
and n
Positive order of ( From small to large ) Array nums1
and nums2
. Please find and return the values of these two positive ordered arrays Median .
example : Input :nums1 = [1,3], nums2 = [2], Output :2.00000
Their thinking :
1. Splice and sort the two arrays
2. Median judgment
var findMedianSortedArrays = function (nums1, nums2) {
let nums3 = nums1.concat(nums2);
let sum = nums3.length / 2;
nums3.sort((a, b) => a - b);
if (nums3.length % 2 !== 0) {
return parseFloat(nums3[Math.floor(sum)]);
} else {
return parseFloat((nums3[sum] + nums3[sum - 1]) / 2);
}
};
边栏推荐
- SSH 远程执行命令简介
- CV in transformer learning notes (continuously updated)
- 199. Right view of binary tree - breadth search
- 2022-2028 global petroleum pipe joint industry research and trend analysis report
- 041. (2.10) talk about manpower outsourcing
- After nohup NPM start &, close the shell window directly, and the process closes accordingly
- Help change the socket position of PCB part
- 204. Count prime
- High concurrency architecture cache
- Reading a line from ifstream into a string variable
猜你喜欢
Getting started with JDBC
KINGS
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
Opencv learning notes (continuously updated)
2022.02.11
Help change the socket position of PCB part
How many convolution methods does deep learning have? (including drawings)
leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]
22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
随机推荐
235. 二叉搜索树的最近公共祖先【lca模板 + 找路径相同】
Record: solve the problem that MySQL is not an internal or external command environment variable
Day-27 database
How about the Moco model?
Processing of user input parameters in shell script
Administrative division code acquisition
How to design a high concurrency system
JS_ Array_ sort
2022.02.11
编程中常见的 Foo 是什么意思?
Mysql45 lecture learning notes (II)
虚拟机和开发板互Ping问题
2022-2028 global marking ink industry research and trend analysis report
TypeScript 官网教程
Opencv learning notes (continuously updated)
Smart wax therapy machine based on STM32 and smart cloud
Torch learning notes (6) -- logistic regression model (self training)
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
MySQL duplicate check
199. Right view of binary tree - breadth search