Skip to content

Commit f944b37

Browse files
committed
Create 1389.按既定顺序创建目标数组.js
1 parent 5342266 commit f944b37

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
直接构建结果数组, 按所在 index 逐个插入
3+
*/
4+
5+
/**
6+
* @param {number[]} nums
7+
* @param {number[]} index
8+
* @return {number[]}
9+
*/
10+
var createTargetArray = function(nums, index) {
11+
const result = [];
12+
for (let i = 0; i < index.length; i++) {
13+
result.splice(index[i], 0, nums[i]);
14+
}
15+
return result;
16+
};

0 commit comments

Comments
 (0)