Skip to content

Commit f19e168

Browse files
committed
Add solution #2390
1 parent 56b77ec commit f19e168

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
2215|[Find the Difference of Two Arrays](./2215-find-the-difference-of-two-arrays.js)|Easy|
391391
2235|[Add Two Integers](./2235-add-two-integers.js)|Easy|
392392
2244|[Minimum Rounds to Complete All Tasks](./2244-minimum-rounds-to-complete-all-tasks.js)|Medium|
393+
2390|[Removing Stars From a String](./2390-removing-stars-from-a-string.js)|Medium|
393394
2396|[Strictly Palindromic Number](./2396-strictly-palindromic-number.js)|Medium|
394395
2413|[Smallest Even Multiple](./2413-smallest-even-multiple.js)|Easy|
395396
2427|[Number of Common Factors](./2427-number-of-common-factors.js)|Easy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* 2390. Removing Stars From a String
3+
* https://leetcode.com/problems/removing-stars-from-a-string/
4+
* Difficulty: Medium
5+
*
6+
* You are given a string s, which contains stars *.
7+
*
8+
* In one operation, you can:
9+
* - Choose a star in s.
10+
* - Remove the closest non-star character to its left, as well as remove the star itself.
11+
*
12+
* Return the string after all stars have been removed.
13+
*
14+
* Note:
15+
* - The input will be generated such that the operation is always possible.
16+
* - It can be shown that the resulting string will always be unique.
17+
*/
18+
19+
/**
20+
* @param {string} s
21+
* @return {string}
22+
*/
23+
var removeStars = function(s) {
24+
const result = [];
25+
for (let i = 0; i < s.length; i++) {
26+
if (s[i] !== '*') {
27+
result.push(s[i]);
28+
} else {
29+
result.pop();
30+
}
31+
}
32+
return result.join('');
33+
};

0 commit comments

Comments
 (0)