Skip to content

Commit 8b66272

Browse files
committed
feat: add ts solution to lc problem: No. 1653
1 parent 32ac4a4 commit 8b66272

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,30 @@ function minimumDeletions(s: string): number {
397397
}
398398
```
399399

400+
<!-- solution:start -->
401+
402+
### Solution 4: Stack
403+
404+
<!-- tabs:start -->
405+
406+
#### TypeScript
407+
408+
```ts
409+
function minimumDeletions(s: string): number {
410+
const stk: string[] = [];
411+
let res = 0;
412+
413+
for (const ch of s) {
414+
if (stk.at(-1) === 'b' && ch === 'a') {
415+
stk.pop();
416+
res++;
417+
} else stk.push(ch);
418+
}
419+
420+
return res;
421+
}
422+
```
423+
400424
<!-- tabs:end -->
401425

402426
<!-- solution:end -->

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,32 @@ function minimumDeletions(s: string): number {
399399

400400
<!-- solution:end -->
401401

402+
<!-- solution:start -->
403+
404+
### Solution 4: Stack
405+
406+
<!-- tabs:start -->
407+
408+
#### TypeScript
409+
410+
```ts
411+
function minimumDeletions(s: string): number {
412+
const stk: string[] = [];
413+
let res = 0;
414+
415+
for (const ch of s) {
416+
if (stk.at(-1) === 'b' && ch === 'a') {
417+
stk.pop();
418+
res++;
419+
} else stk.push(ch);
420+
}
421+
422+
return res;
423+
}
424+
```
425+
426+
<!-- tabs:end -->
427+
428+
<!-- solution:end -->
429+
402430
<!-- problem:end -->
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function minimumDeletions(s: string): number {
2+
const stk: string[] = [];
3+
let res = 0;
4+
5+
for (const ch of s) {
6+
if (stk.at(-1) === 'b' && ch === 'a') {
7+
stk.pop();
8+
res++;
9+
} else stk.push(ch);
10+
}
11+
12+
return res;
13+
}

0 commit comments

Comments
 (0)