Skip to content

Commit 730cfe6

Browse files
committed
Add solution #3174
1 parent 1470bc9 commit 730cfe6

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@
577577
3110|[Score of a String](./3110-score-of-a-string.js)|Easy|
578578
3151|[Special Array I](./3151-special-array-i.js)|Easy|
579579
3160|[Find the Number of Distinct Colors Among the Balls](./3160-find-the-number-of-distinct-colors-among-the-balls.js)|Medium|
580+
3174|[Clear Digits](./3174-clear-digits.js)|Easy|
580581
3223|[Minimum Length of String After Operations](./3223-minimum-length-of-string-after-operations.js)|Medium|
581582
3392|[Count Subarrays of Length Three With a Condition](./3392-count-subarrays-of-length-three-with-a-condition.js)|Easy|
582583
3396|[Minimum Number of Operations to Make Elements in Array Distinct](./3396-minimum-number-of-operations-to-make-elements-in-array-distinct.js)|Easy|

solutions/3174-clear-digits.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 3174. Clear Digits
3+
* https://leetcode.com/problems/clear-digits/
4+
* Difficulty: Easy
5+
*
6+
* You are given a string s.
7+
*
8+
* Your task is to remove all digits by doing this operation repeatedly:
9+
* - Delete the first digit and the closest non-digit character to its left.
10+
*
11+
* Return the resulting string after removing all digits.
12+
*/
13+
14+
/**
15+
* @param {string} s
16+
* @return {string}
17+
*/
18+
var clearDigits = function(s) {
19+
const stack = [];
20+
21+
for (const character of s) {
22+
if (!isNaN(character) && stack.length) {
23+
stack.pop();
24+
} else {
25+
stack.push(character);
26+
}
27+
}
28+
29+
return stack.join('');
30+
};

0 commit comments

Comments
 (0)