All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g1801_1900.s1861_rotating_the_box.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g1801_1900.s1861_rotating_the_box

// #Medium #Array #Matrix #Two_Pointers #2023_06_22_Time_882_ms_(60.00%)_Space_73.6_MB_(80.00%)

class Solution {
    fun rotateTheBox(box: Array): Array {
        val n = box.size
        val m = box[0].size
        val result = Array(m) { CharArray(n) }
        for (i in 0 until n) {
            var j = m - 1
            var idx = m - 1
            while (j >= 0) {
                if (box[i][j] == '#') {
                    result[j--][n - i - 1] = '.'
                    result[idx--][n - i - 1] = '#'
                } else {
                    val c = box[i][j]
                    result[j--][n - i - 1] = c
                    if (c == '*') {
                        idx = j
                    }
                }
            }
        }
        return result
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy