File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 214
214
| 1233| [ 删除子文件夹] ( https://leetcode.cn/problems/remove-sub-folders-from-the-filesystem/ ) | [ JavaScript] ( ./algorithms/remove-sub-folders-from-the-filesystem.js ) | Medium|
215
215
| 1305| [ 两棵二叉搜索树中的所有元素] ( https://leetcode.cn/problems/all-elements-in-two-binary-search-trees/ ) | [ JavaScript] ( ./algorithms/all-elements-in-two-binary-search-trees.js ) | Medium|
216
216
| 1413| [ 逐步求和得到正数的最小值] ( https://leetcode.cn/problems/minimum-value-to-get-positive-step-by-step-sum/ ) | [ JavaScript] ( ./algorithms/minimum-value-to-get-positive-step-by-step-sum.js ) | Easy|
217
+ | 1487| [ 保证文件名唯一] ( https://leetcode.cn/problems/making-file-names-unique/ ) | [ JavaScript] ( ./algorithms/making-file-names-unique.js ) | Medium|
217
218
| 1604| [ 警告一小时内使用相同员工卡大于等于三次的人] ( https://leetcode.cn/problems/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/ ) | [ JavaScript] ( ./algorithms/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period.js ) | Medium|
218
219
| 1664| [ 生成平衡数组的方案数] ( https://leetcode.cn/problems/ways-to-make-a-fair-array/ ) | [ JavaScript] ( ./algorithms/ways-to-make-a-fair-array.js ) | Medium|
219
220
| 1669| [ 合并两个链表] ( https://leetcode.cn/problems/merge-in-between-linked-lists/ ) | [ JavaScript] ( ./algorithms/merge-in-between-linked-lists.js ) | Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1487. 保证文件名唯一
3
+ * @param {string[] } names
4
+ * @return {string[] }
5
+ */
6
+ var getFolderNames = function ( names ) {
7
+ let map = new Map ( ) ;
8
+
9
+ for ( let i = 0 ; i < names . length ; i ++ ) {
10
+ const name = names [ i ] ;
11
+ if ( map . has ( name ) ) {
12
+ let cnt = map . get ( name ) ;
13
+ while ( map . has ( names [ i ] ) ) {
14
+ names [ i ] = `${ name } (${ cnt ++ } )` ;
15
+ }
16
+ map . set ( names [ i ] , 1 ) ; // new name
17
+ map . set ( name , cnt ) ;
18
+ } else {
19
+ map . set ( name , 1 ) ;
20
+ }
21
+ }
22
+
23
+ return names ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments