File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 390
390
2215|[ Find the Difference of Two Arrays] ( ./2215-find-the-difference-of-two-arrays.js ) |Easy|
391
391
2235|[ Add Two Integers] ( ./2235-add-two-integers.js ) |Easy|
392
392
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|
393
394
2396|[ Strictly Palindromic Number] ( ./2396-strictly-palindromic-number.js ) |Medium|
394
395
2413|[ Smallest Even Multiple] ( ./2413-smallest-even-multiple.js ) |Easy|
395
396
2427|[ Number of Common Factors] ( ./2427-number-of-common-factors.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments