Open jajaplus opened 5 years ago
https://leetcode-cn.com/problems/median-of-two-sorted-arrays/submissions/
/** * @param {number[]} nums1 * @param {number[]} nums2 * @return {number} */ var findMedianSortedArrays = function(nums1, nums2) { let totalNum = nums1.length + nums2.length let isEven = totalNum%2 === 0 let middleIndex = parseInt((totalNum-1)/2) let index1 = 0 let index2 = 0 let sortedArr = [] while(sortedArr.length<totalNum){ if(index1===nums1.length){ sortedArr = sortedArr.concat(nums2.slice(index2)) }else if(index2===nums2.length){ sortedArr = sortedArr.concat(nums1.slice(index1)) }else if(nums1[index1]<nums2[index2]){ sortedArr.push(nums1[index1]) index1++ }else{ sortedArr.push(nums2[index2]) index2++ } } if(isEven){ return (sortedArr[middleIndex]+sortedArr[middleIndex+1])/2 }else{ return sortedArr[middleIndex] } };
https://www.freecodecamp.org/news/quick-intro-to-recursion/
用于处理单个有序,多个无序的数组,用来排序。
https://juejin.im/post/5d3e3706f265da1b60294c1f
算法
https://leetcode-cn.com/problems/median-of-two-sorted-arrays/submissions/
阅读
https://www.freecodecamp.org/news/quick-intro-to-recursion/
归并排序
用于处理单个有序,多个无序的数组,用来排序。
分享(js的五个不良的编码习惯)
https://juejin.im/post/5d3e3706f265da1b60294c1f