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

g2101_2200.s2103_rings_and_rods.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.28
Show newest version
package g2101_2200.s2103_rings_and_rods

// #Easy #String #Hash_Table #2023_06_25_Time_131_ms_(89.47%)_Space_33.9_MB_(100.00%)

class Solution {
    fun countPoints(rings: String): Int {
        val redHashMap: MutableMap = HashMap()
        val greenHashMap: MutableMap = HashMap()
        val blueHashMap: MutableMap = HashMap()
        run {
            var i = 0
            while (i <= rings.length - 2) {
                val charOne = rings[i]
                val charTwo = rings[i + 1]
                if (charOne == 'R') {
                    redHashMap[Character.getNumericValue(charTwo)] = 123
                } else if (charOne == 'G') {
                    greenHashMap[Character.getNumericValue(charTwo)] = 123
                } else {
                    blueHashMap[Character.getNumericValue(charTwo)] = 123
                }
                i = i + 2
            }
        }
        var result = 0
        for (i in 0..9) {
            if (redHashMap.containsKey(i) &&
                greenHashMap.containsKey(i) &&
                blueHashMap.containsKey(i)
            ) {
                result++
            }
        }
        return result
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy