Description
Given two arrays nums and index. Create a target array by inserting nums[i] at position index[i] in target. Return the target array.
Examples
Input:
nums = [0,1,2,3,4], index = [0,1,2,2,1]Output:
[0,4,1,3,2]Explanation:
Insert in order.
Input:
nums = [5], index = [0]Output:
[5]Explanation:
With only one element, nums[0]=5 is inserted at index[0]=0, creating the target array [5].
Input:
nums = [10,20,30], index = [2,0,1]Output:
[20,30,10]Explanation:
Step by step: Insert 10 at index 2 → [10]. Insert 20 at index 0 → [20,10]. Insert 30 at index 1 → [20,30,10]. This shows how elements shift when inserting at earlier positions.
Constraints
- •
1 ≤ nums.length ≤ 100