image_2021-10-26_02-13-29.png
38.2 KB
#N1389. Create Target Array in the Given Order
problem link=>https://leetcode.com/problems/create-target-array-in-the-given-order/
#solution
problem link=>https://leetcode.com/problems/create-target-array-in-the-given-order/
#solution
class Solution {
public int[] createTargetArray(int[] nums, int[] index) {
int[] target = new int[nums.length];
int i = 0, k = 0;
while (i < index.length) {
for (k = target.length - 1; k > index[i]; k--)
target[k] = target[k - 1];
target[index[i]] = nums[i];
i++;
}
return target;
}
}
‼️P.s. Without ArrayLists. It would be simple and no-logic with ArrayLists