187. 重复的DNA序列_字符串_中等

 

 水过去

class Solution {
    public List<String> findRepeatedDnaSequences(String s) {
        HashMap<String, Integer> hashMap = new HashMap<>();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            if (i + 9 >= s.length()) break;
            String temp = s.substring(i, i + 10);
            if (hashMap.containsKey(temp)) {
                Integer integer = hashMap.get(temp);
                integer += 1;
                hashMap.put(temp, integer);
            }else{
                hashMap.put(temp,1);
            }
        }
        for (Map.Entry<String, Integer> entry : hashMap.entrySet()) {
//            System.out.println(entry);
            if (entry.getValue() > 1) {
                list.add(entry.getKey());
            }
        }
        return list;
    }
}

 

posted @ 2021-09-27 21:40  你的雷哥  阅读(26)  评论(0编辑  收藏  举报