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

g1201_1300.s1207_unique_number_of_occurrences.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g1201_1300.s1207_unique_number_of_occurrences

// #Easy #Array #Hash_Table #2023_06_10_Time_151_ms_(83.00%)_Space_33.9_MB_(100.00%)

class Solution {
    fun uniqueOccurrences(arr: IntArray): Boolean {
        val map: MutableMap = HashMap()
        for (j in arr) {
            if (map.containsKey(j)) {
                map[j] = map[j]!! + 1
            } else {
                map[j] = 1
            }
        }
        // map for check unique number of count
        val uni: MutableMap = HashMap()
        for (`val` in map.values) {
            if (uni.containsKey(`val`)) {
                return false
            } else {
                uni[`val`] = 1
            }
        }
        return true
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy