![JAR search and dependency download from the Maven repository](/logo.png)
g2401_2500.s2405_optimal_partition_of_string.Solution.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-kotlin Show documentation
Show all versions of leetcode-in-kotlin Show documentation
Kotlin-based LeetCode algorithm problem solutions, regularly updated
package g2401_2500.s2405_optimal_partition_of_string
// #Medium #String #Hash_Table #Greedy #2023_07_03_Time_185_ms_(100.00%)_Space_38_MB_(70.00%)
class Solution {
fun partitionString(s: String): Int {
var count = 1
var arr = BooleanArray(26)
for (c in s.toCharArray()) {
if (arr[c.code - 'a'.code]) {
count++
arr = BooleanArray(26)
}
arr[c.code - 'a'.code] = true
}
return count
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy