-
977. Squares of a Sorted Array javaLeetCode_Study_Plan/Algorithm 2022. 12. 20. 22:16
https://leetcode.com/problems/squares-of-a-sorted-array/
class Solution { public int[] sortedSquares(int[] nums) { int[] ans = new int[nums.length]; for (int i = 0; i < nums.length; i++) { ans[i] = (int) Math.pow(nums[i],2); } Arrays.sort(ans); return ans; } }
** Math.pow를 사용함에 있어 (int) 없이 쓰려고 하니 에러가 떴다.
possible lossy conversion from double to int
그래서 관련되어 에러를 찾아보니 pow를 통해 정수 결과를 얻고 싶으면 타입에 대한 캐스팅이 필요한 것 같다.
해당 내용만 채워주니 바로 문제를 통과할 수 있었다.
'LeetCode_Study_Plan > Algorithm' 카테고리의 다른 글
283. Move Zeroes java (0) 2022.12.20 🎵 189. Rotate Array java (0) 2022.12.20 35. Search Insert Position java (0) 2022.12.20 278. First Bad Version java (0) 2022.12.20 704. Binary Search java (0) 2022.12.20