Kotlin Leetcode - 977. Squares of a Sorted Array
class Solution {
fun sortedSquares(nums: IntArray): IntArray {
}
}
解題思路
這一題考的是對陣列的處理
我們可以用 map()
的方式
來處理陣列內的每個元素
Kotlin 參考解答
class Solution {
fun sortedSquares(nums: IntArray): IntArray = nums
.map { it * it }
.sorted()
.toIntArray()
}
回到 leetcode 列表