当前位置:网站首页>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);
}
};边栏推荐
- What does foo mean in programming?
- Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
- There are several levels of personal income tax
- Help change the socket position of PCB part
- 知其然,而知其所以然,JS 对象创建与继承【汇总梳理】
- 简述服务量化分析体系
- Pan for in-depth understanding of the attention mechanism in CV
- Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time
- 041. (2.10) talk about manpower outsourcing
- PHP determines which constellation it belongs to today
猜你喜欢

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Does SQL always report foreign key errors when creating tables?

Implementation of cqrs architecture mode under Kratos microservice framework

FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试

2022-2028 global solid phase extraction column industry research and trend analysis report

Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download

Torch learning notes (3) -- univariate linear regression model (self training)
![235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]](/img/f5/f2d244e7f19e9ddeebf070a1d06dce.png)
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]

2022-2028 global scar care product industry research and trend analysis report

平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
随机推荐
User identity used by startup script and login script in group policy
Torch learning notes (6) -- logistic regression model (self training)
235. 二叉搜索树的最近公共祖先【lca模板 + 找路径相同】
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
编程中常见的 Foo 是什么意思?
12、 Service management
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
SSH 远程执行命令简介
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
MySQL duplicate check
2022.02.11
SQL custom collation
TypeScript 官网教程
Sqlalchemy - subquery in a where clause - Sqlalchemy - subquery in a where clause
Boost. Asio Library
leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
[combinatorics] exponential generating function (proving that the exponential generating function solves the arrangement of multiple sets)
Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
application
[leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难