码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]187 Repeated DNA Sequences

时间:2015-02-26 00:04:28      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:leetcode

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

    public List<String> findRepeatedDnaSequences(String s) {
        
        // Assumptions...
        
        List<String> toReturn = new ArrayList<>();
        
        Set<String> seen = new HashSet<>();
        
        for (int i = 0 ; i <= s.length() - 10 ; i ++)
        {
            String sub = s.substring(i, i + 10);
            if (seen.contains(sub))
            {
                toReturn.add(sub);
            }
            else
            {
                seen.add(sub);
            }
        }
        return toReturn;
    }


[LeetCode]187 Repeated DNA Sequences

标签:leetcode

原文地址:http://7371901.blog.51cto.com/7361901/1615197

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!