Untitled
unknown
kotlin
a year ago
560 B
7
Indexable
class NumMatrix(matrix: Array<IntArray>) {
val sumMatrix: Array<IntArray>
init {
this.sumMatrix = Array<IntArray>(matrix.size) {IntArray()}
matrix.forEachIndexed { rowIndex, row ->
sumMatrix[rowIndex] = IntArray(row.size)
var sum = 0
row.forEachIndexed { colIndex, value ->
sum += value
sumMatrix[rowIndex][colIndex] = sum
}
}
}
fun sumRegion(row1: Int, col1: Int, row2: Int, col2: Int): Int {
return 1
}
}Editor is loading...
Leave a Comment