File tree 3 files changed +55
-0
lines changed
solution/1400-1499/1487.Making File Names Unique
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,26 @@ func getFolderNames(names []string) []string {
177
177
}
178
178
```
179
179
180
+ ### ** TypeScript**
181
+
182
+ ``` ts
183
+ function getFolderNames(names : string []): string [] {
184
+ let d: Map <string , number > = new Map ();
185
+ for (let i = 0 ; i < names .length ; ++ i ) {
186
+ if (d .has (names [i ])) {
187
+ let k: number = d .get (names [i ]) || 0 ;
188
+ while (d .has (names [i ] + ' (' + k + ' )' )) {
189
+ ++ k ;
190
+ }
191
+ d .set (names [i ], k );
192
+ names [i ] += ' (' + k + ' )' ;
193
+ }
194
+ d .set (names [i ], 1 );
195
+ }
196
+ return names ;
197
+ }
198
+ ```
199
+
180
200
### ** ...**
181
201
182
202
```
Original file line number Diff line number Diff line change @@ -141,6 +141,26 @@ func getFolderNames(names []string) []string {
141
141
}
142
142
```
143
143
144
+ ### ** TypeScript**
145
+
146
+ ``` ts
147
+ function getFolderNames(names : string []): string [] {
148
+ let d: Map <string , number > = new Map ();
149
+ for (let i = 0 ; i < names .length ; ++ i ) {
150
+ if (d .has (names [i ])) {
151
+ let k: number = d .get (names [i ]) || 0 ;
152
+ while (d .has (names [i ] + ' (' + k + ' )' )) {
153
+ ++ k ;
154
+ }
155
+ d .set (names [i ], k );
156
+ names [i ] += ' (' + k + ' )' ;
157
+ }
158
+ d .set (names [i ], 1 );
159
+ }
160
+ return names ;
161
+ }
162
+ ```
163
+
144
164
### ** ...**
145
165
146
166
```
Original file line number Diff line number Diff line change
1
+ function getFolderNames ( names : string [ ] ) : string [ ] {
2
+ let d : Map < string , number > = new Map ( ) ;
3
+ for ( let i = 0 ; i < names . length ; ++ i ) {
4
+ if ( d . has ( names [ i ] ) ) {
5
+ let k : number = d . get ( names [ i ] ) || 0 ;
6
+ while ( d . has ( names [ i ] + '(' + k + ')' ) ) {
7
+ ++ k ;
8
+ }
9
+ d . set ( names [ i ] , k ) ;
10
+ names [ i ] += '(' + k + ')' ;
11
+ }
12
+ d . set ( names [ i ] , 1 ) ;
13
+ }
14
+ return names ;
15
+ }
You can’t perform that action at this time.
0 commit comments