Python code, difference between array and set


  • 0
    W
    class Solution(object):
        def findRepeatedDnaSequences(self, s):
            """
            :type s: str
            :rtype: List[str]
            """
            n,record,re=len(s),set(),[]
            for i in range(n-9):
                x=s[i:i+10]
                if x not in record:
                    record.add(x)
                elif x not in re:
                    re.append(x)
            return re
    

    TLE when record is array, AC when it is set.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.