LeetCode Entry
2390. Removing Stars From a String
we can use a Stack, or just StringBuilder
2390. Removing Stars From a String medium
fun removeStars(s: String): String = StringBuilder().apply {
s.forEach {
if (it == '*') setLength(length - 1)
else append(it)
}
}.toString()
Join me on Telegram
https://t.me/leetcode_daily_unstoppable/177
Intuition
Iterate over a string. When * symbol met, remove last character, otherwise add it.
Approach
- we can use a
Stack, or justStringBuilderComplexity
- Time complexity:
- Space complexity: