LeetCode: Squares of a Sorted Array



問題を解く


入力したarray値を2乗して昇順に並べ替えます.
import java.util.*;
class Solution {
    public int[] sortedSquares(int[] nums) {
        int[] answer = new int[nums.length];
        for(int index = 0; index < nums.length; index++) {
            answer[index] = nums[index] * nums[index];
        }
        Arrays.sort(answer);
        return answer;
    }
}