Class Solution
java.lang.Object
g1401_1500.s1487_making_file_names_unique.Solution
1487 - Making File Names Unique.<p>Medium</p>
<p>Given an array of strings <code>names</code> of size <code>n</code>. You will create <code>n</code> folders in your file system <strong>such that</strong> , at the <code>i<sup>th</sup></code> minute, you will create a folder with the name <code>names[i]</code>.</p>
<p>Since two files <strong>cannot</strong> have the same name, if you enter a folder name that was previously used, the system will have a suffix addition to its name in the form of <code>(k)</code>, where, <code>k</code> is the <strong>smallest positive integer</strong> such that the obtained name remains unique.</p>
<p>Return <em>an array of strings of length</em> <code>n</code> where <code>ans[i]</code> is the actual name the system will assign to the <code>i<sup>th</sup></code> folder when you create it.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> names = [“pes”,“fifa”,“gta”,“pes(2019)”]</p>
<p><strong>Output:</strong> [“pes”,“fifa”,“gta”,“pes(2019)”]</p>
<p><strong>Explanation:</strong> Let’s see how the file system creates folder names:</p>
<p>“pes” –> not assigned before, remains “pes”</p>
<p>“fifa” –> not assigned before, remains “fifa”</p>
<p>“gta” –> not assigned before, remains “gta”</p>
<p>“pes(2019)” –> not assigned before, remains “pes(2019)”</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> names = [“gta”,“gta(1)”,“gta”,“avalon”]</p>
<p><strong>Output:</strong> [“gta”,“gta(1)”,“gta(2)”,“avalon”]</p>
<p><strong>Explanation:</strong> Let’s see how the file system creates folder names:</p>
<p>“gta” –> not assigned before, remains “gta”</p>
<p>“gta(1)” –> not assigned before, remains “gta(1)”</p>
<p>“gta” –> the name is reserved, system adds (k), since “gta(1)” is also reserved, systems put k = 2. it becomes “gta(2)”</p>
<p>“avalon” –> not assigned before, remains “avalon”</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> names = [“onepiece”,“onepiece(1)”,“onepiece(2)”,“onepiece(3)”,“onepiece”]</p>
<p><strong>Output:</strong> [“onepiece”,“onepiece(1)”,“onepiece(2)”,“onepiece(3)”,“onepiece(4)”]</p>
<p><strong>Explanation:</strong> When the last folder is created, the smallest positive valid k is 4, and it becomes “onepiece(4)”.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= names.length <= 5 * 10<sup>4</sup></code></li>
<li><code>1 <= names[i].length <= 20</code></li>
<li><code>names[i]</code> consists of lowercase English letters, digits, and/or round brackets.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
getFolderNames
-