Skip to content

Commit fc15c77

Browse files
authored
Create 2390-removing-stars-from-a-strin.kt
1 parent 6e5b69b commit fc15c77

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: kotlin/2390-removing-stars-from-a-strin.kt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun removeStars(s: String): String {
3+
val stack = LinkedList<Char>()
4+
5+
for (c in s) {
6+
if (c == '*' && stack.isNotEmpty()) {
7+
stack.removeLast()
8+
} else {
9+
stack.addLast(c)
10+
}
11+
}
12+
13+
return stack.joinToString("")
14+
}
15+
}

0 commit comments

Comments
 (0)