当前位置:网站首页>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);
}
};
边栏推荐
- 硬盘监控和分析工具:Smartctl
- Coordinate layer conversion tool (video)
- VLAN experiment
- Kratos微服务框架下实现CQRS架构模式
- Add control at the top of compose lazycolumn
- [leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难
- CTO and programmer were both sentenced for losing control of the crawler
- “google is not defined” when using Google Maps V3 in Firefox remotely
- Su embedded training - Day10
- leetcode:556. 下一个更大元素 III【模拟 + 尽可能少变更】
猜你喜欢
Administrative division code acquisition
虚拟机和开发板互Ping问题
2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
Torch learning notes (3) -- univariate linear regression model (self training)
Install apache+php+mysql+phpmyadmin xampp and its error resolution
How many convolution methods does deep learning have? (including drawings)
Zhengda futures news: soaring oil prices may continue to push up global inflation
Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download
我眼中真正优秀的CTO长啥样
CTO and programmer were both sentenced for losing control of the crawler
随机推荐
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
Implementation of cqrs architecture mode under Kratos microservice framework
Does SQL always report foreign key errors when creating tables?
235. 二叉搜索樹的最近公共祖先【lca模板 + 找路徑相同】
Unity webgl optimization
Scrapy爬虫框架
User identity used by startup script and login script in group policy
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
php-fpm的max_chindren的一些误区
Getting started with JDBC
Raft 日志复制
__ Weak and__ The difference between blocks
Record: MySQL changes the time zone
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
JS_ Array_ sort
Software development freelancer's Road
flask 生成swagger文档
How to design a high concurrency system
2022.02.11
Transformer T5 model read slowly