Skip to content

Commit 9562bfa

Browse files
authored
Create 1389-create-target-array-in-the-given-order.js
1 parent 9f86ed0 commit 9562bfa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @param {number[]} index
4+
* @return {number[]}
5+
*/
6+
const createTargetArray = function(nums, index) {
7+
const res = [], n = nums.length
8+
for(let i = 0; i < n; i++) {
9+
if(res[index[i]] == null) res[index[i]] = nums[i]
10+
else res.splice(index[i], 0, nums[i])
11+
12+
}
13+
14+
return res
15+
};

0 commit comments

Comments
 (0)