Kotlin建立二維Int陣列

HandKnock發表於2021-01-04
fun transpose(A: Array<IntArray>): Array<IntArray> {
    var R = A.size
    var C = A[0].size
    val ans = Array(size = C, init = { IntArray(R) })
    for (i in 0 until R) {
        for (j in 0 until C) {
            ans[j][i] = A[i][j]
        }
    }
    return ans
}

相關文章