# 解法1：暴力TLE

class Solution:
def getFolderNames(self, names: List[str]) -> List[str]:
seen = {}
ans = []
for name in names:
if name not in seen:
ans.append(name)
seen[name] = True
else:
for i in range(1,1000000):
new_name = name+'('+ str(i)+')'
if new_name not in seen:
ans.append(new_name)
seen[new_name] = True
break
return ans


# 解法2：hashmap

class Solution:
def getFolderNames(self, names: List[str]) -> List[str]:
# main idea: store the previous appeared names and its appeared times; when see a name, if it has not appeared before, we simply append to the answer; otherwise, we keep updating the name using the previous appeared times of this name

# a dict store the name and appeared times pair
seen = {}
ans = []

for name in names:
# get the number of times that this name previously appeared
count = seen.get(name,0)
# save the current name for later update usage
prev_name = name

# if count>0, means this name has appeared before
if count>0:
# we update it use the previous appeared times, until create a new name
while prev_name in seen:
prev_name = name + '('+str(count)+')'
count += 1
# only update the count of the name when the name has appeared previously. update the count of the previous appeared name to count, so we can quickly found the number when we encounter same name
seen[name] = count
# the prev_name is now a new name no matter count bigger or smaller than 0, we initialize the count to be 1
seen[prev_name] = 1
ans.append(prev_name)

return ans


08-20
03-30
09-18
01-27