File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1- # 1,325 LeetCode solutions in JavaScript
1+ # 1,326 LeetCode solutions in JavaScript
22
33[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
44
113611361482|[ Minimum Number of Days to Make m Bouquets] ( ./solutions/1482-minimum-number-of-days-to-make-m-bouquets.js ) |Medium|
113711371483|[ Kth Ancestor of a Tree Node] ( ./solutions/1483-kth-ancestor-of-a-tree-node.js ) |Hard|
113811381486|[ XOR Operation in an Array] ( ./solutions/1486-xor-operation-in-an-array.js ) |Easy|
1139+ 1487|[ Making File Names Unique] ( ./solutions/1487-making-file-names-unique.js ) |Medium|
113911401491|[ Average Salary Excluding the Minimum and Maximum Salary] ( ./solutions/1491-average-salary-excluding-the-minimum-and-maximum-salary.js ) |Easy|
114011411492|[ The kth Factor of n] ( ./solutions/1492-the-kth-factor-of-n.js ) |Medium|
114111421493|[ Longest Subarray of 1's After Deleting One Element] ( ./solutions/1493-longest-subarray-of-1s-after-deleting-one-element.js ) |Medium|
Original file line number Diff line number Diff line change 1+ /**
2+ * 1487. Making File Names Unique
3+ * https://leetcode.com/problems/making-file-names-unique/
4+ * Difficulty: Medium
5+ *
6+ * Given an array of strings names of size n. You will create n folders in your file system such
7+ * that, at the ith minute, you will create a folder with the name names[i].
8+ *
9+ * Since two files cannot have the same name, if you enter a folder name that was previously used,
10+ * the system will have a suffix addition to its name in the form of (k), where, k is the smallest
11+ * positive integer such that the obtained name remains unique.
12+ *
13+ * Return an array of strings of length n where ans[i] is the actual name the system will assign
14+ * to the ith folder when you create it.
15+ */
16+
17+ /**
18+ * @param {string[] } names
19+ * @return {string[] }
20+ */
21+ var getFolderNames = function ( names ) {
22+ const map = new Map ( ) ;
23+ const result = [ ] ;
24+
25+ for ( const name of names ) {
26+ if ( ! map . has ( name ) ) {
27+ result . push ( name ) ;
28+ map . set ( name , 1 ) ;
29+ } else {
30+ let suffix = map . get ( name ) ;
31+ let newName = `${ name } (${ suffix } )` ;
32+ while ( map . has ( newName ) ) {
33+ suffix ++ ;
34+ newName = `${ name } (${ suffix } )` ;
35+ }
36+ result . push ( newName ) ;
37+ map . set ( name , suffix + 1 ) ;
38+ map . set ( newName , 1 ) ;
39+ }
40+ }
41+
42+ return result ;
43+ } ;
You can’t perform that action at this time.
0 commit comments