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

g2301_2400.s2351_first_letter_to_appear_twice.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.32
Show newest version
package g2301_2400.s2351_first_letter_to_appear_twice

// #Easy #String #Hash_Table #Counting #2023_07_02_Time_122_ms_(100.00%)_Space_33.4_MB_(100.00%)

class Solution {
    fun repeatedCharacter(s: String): Char {
        val n = s.length
        val hm = IntArray(26)
        for (i in 0 until n) {
            val c = s[i]
            hm[c.code - 'a'.code]++
            if (hm[c.code - 'a'.code] > 1) {
                return c
            }
        }
        return '0'
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy