|
3 | 3 | importjava.util.ArrayList; |
4 | 4 | importjava.util.List; |
5 | 5 |
|
6 | | -/** |
7 | | - * 1389. Create Target Array in the Given Order |
8 | | - * |
9 | | - * Given two arrays of integers nums and index. Your task is to create target array under the following rules: |
10 | | - * Initially target array is empty. |
11 | | - * From left to right read nums[i] and index[i], insert at index index[i] the value 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 | | - * Example 1: |
18 | | - * Input: nums = [0,1,2,3,4], index = [0,1,2,2,1] |
19 | | - * Output: [0,4,1,3,2] |
20 | | - * Explanation: |
21 | | - * nums index target |
22 | | - * 0 0 [0] |
23 | | - * 1 1 [0,1] |
24 | | - * 2 2 [0,1,2] |
25 | | - * 3 2 [0,1,3,2] |
26 | | - * 4 1 [0,4,1,3,2] |
27 | | - * |
28 | | - * Example 2: |
29 | | - * Input: nums = [1,2,3,4,0], index = [0,1,2,3,0] |
30 | | - * Output: [0,1,2,3,4] |
31 | | - * Explanation: |
32 | | - * nums index target |
33 | | - * 1 0 [1] |
34 | | - * 2 1 [1,2] |
35 | | - * 3 2 [1,2,3] |
36 | | - * 4 3 [1,2,3,4] |
37 | | - * 0 0 [0,1,2,3,4] |
38 | | - * |
39 | | - * Example 3: |
40 | | - * Input: nums = [1], index = [0] |
41 | | - * Output: [1] |
42 | | - * |
43 | | - * Constraints: |
44 | | - * 1 <= nums.length, index.length <= 100 |
45 | | - * nums.length == index.length |
46 | | - * 0 <= nums[i] <= 100 |
47 | | - * 0 <= index[i] <= i |
48 | | - * */ |
49 | 6 | publicclass_1389 { |
50 | 7 | publicstaticclassSolution1 { |
51 | 8 | publicint[]createTargetArray(int[]nums,int[]index) { |
|