g2701_2800.s2788_split_strings_by_separator.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 g2701_2800.s2788_split_strings_by_separator
// #Easy #Array #String #2023_08_08_Time_314_ms_(85.45%)_Space_38_MB_(98.18%)
class Solution {
fun splitWordsBySeparator(words: List, separator: Char): List {
val list: MutableList = ArrayList()
for (str in words) {
var si = 0
for (i in str.indices) {
if (str[i] == separator) {
if (i > si) {
list.add(str.substring(si, i))
}
si = i + 1
}
}
if (si != str.length) {
list.add(str.substring(si, str.length))
}
}
return list
}
}