What's the shortcomings or disadvantages of my solution?


  • 0
    P
    public List<String> findRepeatedDnaSequences(String s) {
        List<String> result = new ArrayList<String>();
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        if(s == null || s.length() <= 10) return result;
        int len = s.length();
        for(int i = 0; i <= len-10; i++){
            String dna = s.substring(i, i+10);
            if(map.containsKey(dna)){
                 if(map.get(dna) == 1){
                     result.add(dna);
                     map.put(dna, 2);
                 }
            }
            else{
                map.put(dna, 1);
            }
        }
        return result;
    }
    

    anyone could give me a hint? I really appreciate the help.


  • 0
    P

    I figured one out by myself: using hashmap to store the whole substrings is too memory cost, instead, we should use bitmap to convert substring to an int to compare, is that right?


Log in to reply
 

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