https://leetcode.com/problems/squares-of-a-sorted-array/
Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.
배열값을 제곱한 수를 오름차순 정렬
class Solution {
public int[] sortedSquares(int[] nums) {
int[] arr = new int[nums.length];
for(int i=0; i<nums.length; i++){
arr[i] = nums[i] * nums[i];
}
Arrays.sort(arr);
return arr;
}
}
새로운 배열 arr 정의해서 제곱값을 넣음
Arrays.sort() 함수를 사용하여 arr 정렬
좋은 글 감사합니다. 자주 올게요 :)