Wrong Answer- It says (Can any one help me identify the bug in the code please)


  • 0
    V

    public class Solution {
    public List<String> findRepeatedDnaSequences(String s) {

     List<String> ls = new LinkedList<String>();
     
     if(s.length()<=10) 
     
        return ls;
        
     HashMap<String,Integer> cnt = new HashMap<String,Integer>();
        for(int i = 0 ; i <= s.length()-10;i++){
         String curr = s.substring(i,i+10);
         
         if(!cnt.containsKey(curr)){
            // System.out.println(curr);
             cnt.put(curr,1);
             }
         else{
             int currCnt = cnt.get(curr);
             cnt.put(curr,currCnt++);
         }
     } 
     
     for(String str:cnt.keySet()){
         if(cnt.get(str) >1) 
             ls.add(str);
     }
     
    return ls;
        
    }
    

    }


  • 0
    L

    which test case get wrong answer?


  • 0
    V

    Input :"AAAAAAAAAAA"


  • 0
    L

    The answer is {"AAAAAAAAAA"}
    But your answer is {}


  • 0
    V

    @Ictrip Thanks .I found the mistake just now : I should do ++currCnt instead of currCnt++
    programming is fun and debugging is more fun.


Log in to reply
 

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