[ leet_code ] [weekly-contest-194 solution] XOR Operation in an Array, Making File Names Unique
03 Jul 2020
Reading time ~1 minute
문제 : https://leetcode.com/contest/weekly-contest-194
1. XOR Operation in an Array
from functools import reduce
def xorOperation(n: int, start: int) -> int:
return reduce(lambda a, b: a^b, [start + i * 2 for i in range(n)])
2. Making File Names Unique
from collections import defaultdict
def getFolderNames(names: List[str]) -> List[str]:
counted = {}
ans =[]
for name in names:
new_name = name
while new_name in counted:
new_name = name + f"({counted[name]})"
counted[name] += 1
ans.append(new_name)
counted[new_name] = 1
return ans