Skip to content

Commit 814e54c

Browse files
committedOct 15, 2021
Add solution #1389
1 parent 0409840 commit 814e54c

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
1365|[How Many Numbers Are Smaller Than the Current Number](./1365-how-many-numbers-are-smaller-than-the-current-number.js)|Easy|
147147
1374|[Generate a String With Characters That Have Odd Counts](./1374-generate-a-string-with-characters-that-have-odd-counts.js)|Easy|
148148
1380|[Lucky Numbers in a Matrix](./1380-lucky-numbers-in-a-matrix.js)|Easy|
149+
1389|[Create Target Array in the Given Order](./1389-create-target-array-in-the-given-order.js)|Easy|
149150
1472|[Design Browser History](./1472-design-browser-history.js)|Medium|
150151
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
151152
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 1389. Create Target Array in the Given Order
3+
* https://leetcode.com/problems/create-target-array-in-the-given-order/
4+
* Difficulty: Easy
5+
*
6+
* Given two arrays of integers nums and index. Your task is to create target array
7+
* under the following rules:
8+
*
9+
* - Initially target array is empty.
10+
* - From left to right read nums[i] and index[i], insert at index index[i] the value
11+
* nums[i] in target array.
12+
* - Repeat the previous step until there are no elements to read in nums and index.
13+
* - Return the target array.
14+
*
15+
* It is guaranteed that the insertion operations will be valid.
16+
*/
17+
18+
/**
19+
* @param {number[]} nums
20+
* @param {number[]} index
21+
* @return {number[]}
22+
*/
23+
var createTargetArray = function(nums, index) {
24+
const result = [];
25+
index.forEach((i, j) => result.splice(i, 0, nums[j]));
26+
return result;
27+
};

0 commit comments

Comments
 (0)
Please sign in to comment.