Leetcode question 1239: Given an array of strings arr. String s is a concatenation of a sub-sequence of arr which have unique characters. Return the maximum possible length of s.
The following is a solution:
class Solution(object):
def __init__(self):
self.result = 0
def checkDuplicate(self, s):
return len(s) != len(set(s))
def helper(self, arr, index, curr):
self.result = max(self.result, len(curr))
for i in range(index, len(arr)):
temp = curr + arr[i]
if not self.checkDuplicate(temp):
self.helper(arr, i, temp)
def maxLength(self, arr):
"""
:type arr: List[str]
:rtype: int
"""
index = 0
curr = ''
self.helper(arr, index, curr)
return self.result
My question is related to the time complexity of this solution. Will it be O(n^2) ?
question from:
https://stackoverflow.com/questions/65856560/leetcode-maximum-length-of-a-concatenated-string-with-unique-characters 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…