列表

详情


FED62. 删除数组第一个元素

描述

删除数组 arr 第一个元素。不要直接修改数组 arr,结果返回新的数组

示例1

输入:

[1, 2, 3, 4]

输出:

[2, 3, 4]

原站题解

HTML/CSS/JavaScript 解法, 执行用时: 856ms, 内存消耗: 77836KB, 提交时间: 2020-11-27

{"css":"","js":"function curtail(arr) {\n    let arr2 = arr.slice(0);\n    arr2.shift(arr[0])\n    return arr2\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 857ms, 内存消耗: 77852KB, 提交时间: 2020-11-22

{"css":"","js":"function curtail(arr) {\n    return arr.slice(1)\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 863ms, 内存消耗: 77852KB, 提交时间: 2020-11-22

{"css":"","js":"function curtail(arr) {\n    var ar = new Array();\n    for(var i=1;i<arr.length;i++){\n        ar.push(arr[i])\n    }\n    return ar\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 864ms, 内存消耗: 77844KB, 提交时间: 2021-01-08

{"css":"","js":"function curtail(arr) {\n    let copy = arr.slice();\n    copy.shift();\n    return copy\n}","html":"","libs":[]}

HTML/CSS/JavaScript 解法, 执行用时: 866ms, 内存消耗: 77872KB, 提交时间: 2020-12-25

{"css":"","js":"function curtail(arr) {\n    let newArr = [...arr]\n    newArr.splice(0,1)\n    return newArr\n}","html":"","libs":[]}

上一题