Day - 54

Day - 54

Assalamu alaykum, everyone! How are you today? Today I am going to share the solutions of 54th day of my coding challenge!


  1. Problem 4. Median of Two Sorted Arrays

/*
?* @param {number[]} nums1
?* @param {number[]} nums2
?* @return {number}
?*/

var findMedianSortedArrays = function (nums1, nums2) {
? const val = [...nums1, ...nums2].sort(function (a, b) {
? ? return a - b;
? });

? if (val.length % 2 !== 0) {
? ? const median = Math.floor(val.length / 2);
? ? return val[median].toFixed(4);
? } else if (val.length % 2 === 0) {
? ? const med1 = val[val.length / 2 - 1];
? ? const med2 = val[val.length / 2];

? ? const median = (med1 + med2) / 2;

? ? return median.toFixed(4);
? }
};        

I think it is an easy way of getting median of 2 arrays. Then, If you have any solutions that better than mine, let's share it with me and your friends as well.


Already, we passed half of my challenge. We have 46 days and we will successfully complete this challenge! If I think about it, I can not explain how I feel myself. So, let's wait. It will be fine.


Thanks for your attention as well. I am glad to post today's article. I am glad to give something. See you!


#leetcode #coding #challenges #javascript #typescript #algorithms #problems #solutions #programming

要查看或添加评论,请登录

社区洞察

其他会员也浏览了