class Solution {
public int[] squareArray(int[] nums) {
int[] result = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
result[i] = nums[i] * nums[i];
}
return result;
}
}
Explanation: We create a new array and store the square of each element.
β± O(n) | πΎ O(n)