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

g1401_1500.s1487_making_file_names_unique.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.32
Show newest version
package g1401_1500.s1487_making_file_names_unique

// #Medium #Array #String #Hash_Table #2023_06_13_Time_553_ms_(50.00%)_Space_50.7_MB_(50.00%)

class Solution {
    fun getFolderNames(names: Array): Array {
        val map = HashMap()
        for (i in names.indices) {
            var prefix = map.getOrDefault(names[i], 0)
            if (prefix != 0) {
                val raw = names[i]
                while (map.getOrDefault(names[i], 0) != 0) {
                    names[i] = "$raw($prefix)"
                    prefix++
                }
                map[raw] = prefix
            }
            map[names[i]] = 1
        }
        return names
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy