Algorithm/NeetCode

Repeated DNA Sequences

Tony Lim 2024. 11. 7. 13:56
728x90

https://leetcode.com/problems/repeated-dna-sequences/

class Solution:
    def findRepeatedDnaSequences(self, s: str) -> List[str]:
        seen, res = set(), set()

        for l in range(len(s) - 9):
            cur = s[l: l+10]
            if cur in seen:
                res.add(cur)
            else:
                seen.add(cur)
        return list(res)

10개의 substring이 set에있는지 쭉 확인하면서 given string iteration을 하면 된다.

728x90

'Algorithm > NeetCode' 카테고리의 다른 글

First Missing Positive  (1) 2024.11.12
Non-decreasing Array  (2) 2024.11.11
Range Sum Query 2D - Immutable  (0) 2024.11.10
Check If a String Contains All Binary Codes of Size K  (0) 2024.11.09
Insert Delete GetRandom O(1)  (0) 2024.11.08