File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
solution/1800-1899/1898.Maximum Number of Removable Characters Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,35 @@ class Solution {
129
129
}
130
130
```
131
131
132
+ ### ** TypeScript**
133
+
134
+ ``` ts
135
+ function maximumRemovals(s : string , p : string , removable : number []): number {
136
+ let left = 0 , right = removable .length ;
137
+ while (left < right ) {
138
+ let mid = (left + right + 1 ) >> 1 ;
139
+ if (isSub (s , p , new Set (removable .slice (0 , mid )))) {
140
+ left = mid ;
141
+ } else {
142
+ right = mid - 1 ;
143
+ }
144
+ }
145
+ return left ;
146
+ };
147
+
148
+ function isSub(str : string , sub : string , idxes : Set <number >): boolean {
149
+ let m = str .length , n = sub .length ;
150
+ let i = 0 , j = 0 ;
151
+ while (i < m && j < n ) {
152
+ if (! idxes .has (i ) && str .charAt (i ) == sub .charAt (j )) {
153
+ ++ j ;
154
+ }
155
+ ++ i ;
156
+ }
157
+ return j == n ;
158
+ }
159
+ ```
160
+
132
161
### ** ...**
133
162
134
163
```
Original file line number Diff line number Diff line change @@ -117,6 +117,35 @@ class Solution {
117
117
}
118
118
```
119
119
120
+ ### ** TypeScript**
121
+
122
+ ``` ts
123
+ function maximumRemovals(s : string , p : string , removable : number []): number {
124
+ let left = 0 , right = removable .length ;
125
+ while (left < right ) {
126
+ let mid = (left + right + 1 ) >> 1 ;
127
+ if (isSub (s , p , new Set (removable .slice (0 , mid )))) {
128
+ left = mid ;
129
+ } else {
130
+ right = mid - 1 ;
131
+ }
132
+ }
133
+ return left ;
134
+ };
135
+
136
+ function isSub(str : string , sub : string , idxes : Set <number >): boolean {
137
+ let m = str .length , n = sub .length ;
138
+ let i = 0 , j = 0 ;
139
+ while (i < m && j < n ) {
140
+ if (! idxes .has (i ) && str .charAt (i ) == sub .charAt (j )) {
141
+ ++ j ;
142
+ }
143
+ ++ i ;
144
+ }
145
+ return j == n ;
146
+ }
147
+ ```
148
+
120
149
### ** ...**
121
150
122
151
```
Original file line number Diff line number Diff line change
1
+ function maximumRemovals ( s : string , p : string , removable : number [ ] ) : number {
2
+ let left = 0 , right = removable . length ;
3
+ while ( left < right ) {
4
+ let mid = ( left + right + 1 ) >> 1 ;
5
+ if ( isSub ( s , p , new Set ( removable . slice ( 0 , mid ) ) ) ) {
6
+ left = mid ;
7
+ } else {
8
+ right = mid - 1 ;
9
+ }
10
+ }
11
+ return left ;
12
+ } ;
13
+
14
+ function isSub ( str : string , sub : string , idxes : Set < number > ) : boolean {
15
+ let m = str . length , n = sub . length ;
16
+ let i = 0 , j = 0 ;
17
+ while ( i < m && j < n ) {
18
+ if ( ! idxes . has ( i ) && str . charAt ( i ) == sub . charAt ( j ) ) {
19
+ ++ j ;
20
+ }
21
+ ++ i ;
22
+ }
23
+ return j == n ;
24
+ }
You can’t perform that action at this time.
0 commit comments