当前位置:网站首页>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);
}
};
边栏推荐
- Usage of laravel conditional array in
- 简述服务量化分析体系
- C enum contains value - C enum contains value
- Raft log replication
- php-fpm的max_chindren的一些误区
- Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
- What is the function of registering DLLs- What does registering a DLL do?
- Chisel tutorial - 06 Phased summary: implement an FIR filter (chisel implements 4-bit FIR filter and parameterized FIR filter)
- VLAN experiment
- High concurrency architecture cache
猜你喜欢
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
How to quickly view the inheritance methods of existing models in torchvision?
Ping problem between virtual machine and development board
Opencv learning notes (continuously updated)
2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
Zhengda futures news: soaring oil prices may continue to push up global inflation
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
Pan for in-depth understanding of the attention mechanism in CV
What is SQL get connection
随机推荐
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Pytorch introduction to deep learning practice notes 13- advanced chapter of cyclic neural network - Classification
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
Su embedded training - Day10
Pan for in-depth understanding of the attention mechanism in CV
A green plug-in that allows you to stay focused, live and work hard
C enum contains value - C enum contains value
The more you talk, the more your stupidity will be exposed.
Typescript configuration
235. 二叉搜索树的最近公共祖先【lca模板 + 找路径相同】
189. Rotation array
Recent learning experience
[combinatorics] exponential generating function (example of exponential generating function solving multiple set arrangement)
Web3 credential network project galaxy is better than nym?
[combinatorics] exponential generating function (example 2 of solving multiple set permutation with exponential generating function)
Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
php-fpm的max_chindren的一些误区
How can I avoid "div/0!" Errors in Google Docs spreadsheet- How do I avoid the '#DIV/0!' error in Google docs spreadsheet?