Skip to content

Commit 0c27987

Browse files
committed
feat: add js solution to lc problem: No. 1653
1 parent 8b66272 commit 0c27987

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ function minimumDeletions(s: string): number {
421421
}
422422
```
423423

424+
#### JavaScript
425+
426+
```js
427+
/**
428+
* @param {string} s
429+
* @return {number}
430+
*/
431+
var minimumDeletions = function (s) {
432+
const stk = [];
433+
let res = 0;
434+
435+
for (const ch of s) {
436+
if (stk.at(-1) === 'b' && ch === 'a') {
437+
stk.pop();
438+
res++;
439+
} else stk.push(ch);
440+
}
441+
442+
return res;
443+
};
444+
```
445+
424446
<!-- tabs:end -->
425447

426448
<!-- solution:end -->

solution/1600-1699/1653.Minimum Deletions to Make String Balanced/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,28 @@ function minimumDeletions(s: string): number {
423423
}
424424
```
425425

426+
#### JavaScript
427+
428+
```js
429+
/**
430+
* @param {string} s
431+
* @return {number}
432+
*/
433+
var minimumDeletions = function (s) {
434+
const stk = [];
435+
let res = 0;
436+
437+
for (const ch of s) {
438+
if (stk.at(-1) === 'b' && ch === 'a') {
439+
stk.pop();
440+
res++;
441+
} else stk.push(ch);
442+
}
443+
444+
return res;
445+
};
446+
```
447+
426448
<!-- tabs:end -->
427449

428450
<!-- solution:end -->
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var minimumDeletions = function (s) {
6+
const stk = [];
7+
let res = 0;
8+
9+
for (const ch of s) {
10+
if (stk.at(-1) === 'b' && ch === 'a') {
11+
stk.pop();
12+
res++;
13+
} else stk.push(ch);
14+
}
15+
16+
return res;
17+
};

0 commit comments

Comments
 (0)