g0801_0900.s0830_positions_of_large_groups.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 g0801_0900.s0830_positions_of_large_groups
// #Easy #String #2023_03_25_Time_221_ms_(100.00%)_Space_37.2_MB_(85.71%)
class Solution {
fun largeGroupPositions(s: String): List> {
val map: MutableList> = ArrayList()
var i = 0
while (i < s.length) {
var j = i
while (j < s.length && s[j] == s[i]) {
j++
}
if (j - 1 - i + 1 >= 3) {
map.add(listOf(i, j - 1))
}
i = j
}
return map
}
}