当前位置:网站首页>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);
}
};边栏推荐
- 虚拟机和开发板互Ping问题
- Smart wax therapy machine based on STM32 and smart cloud
- Record: solve the problem that MySQL is not an internal or external command environment variable
- CTO and programmer were both sentenced for losing control of the crawler
- Record: MySQL changes the time zone
- Kratos微服务框架下实现CQRS架构模式
- Introduction to SSH Remote execution command
- Record: install MySQL on ubuntu18.04
- Torch learning notes (6) -- logistic regression model (self training)
- [combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
猜你喜欢

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

12、 Service management
![[Godot] add menu button](/img/44/ef1e6ac25bcbc8cc3ecc00c52f8ee2.jpg)
[Godot] add menu button

MySQL duplicate check

2022-2028 global aircraft head up display (HUD) industry research and trend analysis report

Recommend a simple browser tab

Unity webgl optimization

Chisel tutorial - 06 Phased summary: implement an FIR filter (chisel implements 4-bit FIR filter and parameterized FIR filter)
Know what it is, and know why, JS object creation and inheritance [summary and sorting]
![[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*](/img/e8/67961bf8a589869bde2a0aa3e09605.jpg)
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
随机推荐
多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
Which do MySQL and Oracle learn?
Opencv learning notes (continuously updated)
199. Right view of binary tree - breadth search
Transformer T5 model read slowly
2022-2028 global sepsis treatment drug industry research and trend analysis report
High concurrency Architecture - separate databases and tables
application
Compose LazyColumn 顶部添加控件
Does SQL always report foreign key errors when creating tables?
组策略中开机脚本与登录脚本所使用的用户身份
Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download
my. INI file not found
Typescript official website tutorial
The installation path cannot be selected when installing MySQL 8.0.23
Administrative division code acquisition
Smart wax therapy machine based on STM32 and smart cloud
PHP determines which constellation it belongs to today
Zhengda futures news: soaring oil prices may continue to push up global inflation
达梦数据库的物理备份和还原简解