Removing Stars from a String - Leetcode 2390 - Python

preview_player
Показать описание
Leetcode Daily Challenge - April 11, 2023
Leetcode 2390. Removing Stars from a String - Python Solution

Problem Statement
You are given a string s, which contains stars *.
In one operation, you can:
* Choose a star in s.
* Remove the closest non-star character to its left, as well as remove the star itself.
Return the string after all stars have been removed.

Note:
The input will be generated such that the operation is always possible.
It can be shown that the resulting string will always be unique.
===================================================
Key Moments
0:00 Intro to Removing Stars from a String
0:15 Explanation of Removing Stars from a String
0:58 Code for Removing stars from a string
1:59 Results
===================================================
Support the channel by subscribing and hitting the like button.

#leetcode #leetcodesolution #leetcodedailychallenge #codingpractice #learnpython #python #googleinterview #amazoninterviewpreparation
Рекомендации по теме
Комментарии
Автор

The solution idea is fine, but the code would be a lot nicer if you used a for loop instead of a while loop:

```
class Solution:
def removeStars(self, s: str) -> str:
stack = []
for char in s:
if char == "*":
stack.pop()
else:
stack.append(char)
return ''.join(stack)
```

Also, the audio quality is pretty bad.

nikhil_a
visit shbcf.ru