Recca Chao 的 gitHub page

推廣網站開發,包含 Laravel 和 Kotlin 後端撰寫、自動化測試、讀書心得等。Taiwan Kotlin User Group 管理員。

View on GitHub

Kotlin Leetcode - 3925. Concatenate Array With Reverse

題目連接:https://leetcode.com/problems/concatenate-array-with-reverse/

class Solution {
    fun concatWithReverse(nums: IntArray): IntArray {

    }
}

解題思路

這題目是陣列相關操作

透過 Kotlin 內建的 reversedArray()

可以很快的處理掉這一題

Kotlin 參考解答

點擊展開解答
class Solution {
    fun concatWithReverse(nums: IntArray): IntArray {
        return nums + nums.reversedArray()
    }
}