疑惑的问题

  1. leetcode题
    https://leetcode.cn/problems/merge-sorted-array/
    为什么这样不行呢?
let nums1=[1,2,3,0,0,0]
let nums2=[2,5,6]
let m=3
let n=3
var merge = function (nums1, m, nums2, n) {
// 截取数组,等效于去掉末尾的0元素
nums1 = nums1.slice(0, m)
// 连接
nums1 = nums1.concat(nums2)
// 排序,sort会改变原数组
nums1=nums1.sort((a, b) => a - b)
return nums1
};
console.log(merge(nums1,m,nums2,n));
console.log(nums1);

image

本文作者:Code6E

本文链接:https://www.cnblogs.com/road2code/p/17169291.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Code6E  阅读(16)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.