Skip to content

Instantly share code, notes, and snippets.

@Xevion
Created January 14, 2021 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xevion/a5b07906ee9649a0d6aecc2e86e55de0 to your computer and use it in GitHub Desktop.
Save Xevion/a5b07906ee9649a0d6aecc2e86e55de0 to your computer and use it in GitHub Desktop.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Solution {
HashMap<String, Integer> count = new HashMap<String, Integer>();
public String[] getFolderNames(String[] names) {
String[] results = new String[names.length];
for (int i = 0; i < names.length; i++) {
if (count.containsKey(names[i])) {
int k = count.get(names[i]) + 1;
String test;
do {
test = names[i] + "(" + k++ + ")";
} while (count.containsKey(test));
count.put(test, 0);
count.put(names[i], k - 1);
results[i] = test;
} else {
count.put(names[i], 0);
results[i] = names[i];
}
}
return results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment