给出一些字符串,问取其中若干字符串能拼出的不含重复字母的最长字串
先过滤掉自身有重复字母的,然后设一个内含set的列表,每次扫一遍列表看能否加入当前字符串,最后取列表中最多字母的set
#1239
#Runtime: 97 ms (Beats 50%)
#Memory: 53.4 MB (Beats 8.49%)
class Solution(object):
def maxLength(self, arr):
"""
:type arr: List[str]
:rtype: int
"""
candidate = []
for s in arr:
u = set(s)
if len(s) == len(u):
candidate.append(u)
ans = [set()]
maxx = 0
for i in candidate:
for j in ans:
if not i & j:
ans.append(i | j)
maxx = max(maxx, len(i | j))
return maxx