String Similarity

  • + 0 comments

    i got time limit exceed in 2 test cases, how should i modify this code?

    int stringSimilarity(string s) {
        int count=s.size();
        for(int i=1;i<s.size();i++){
            string str = s.substr(i, s.size()-i);
            for(int j=0;j<str.size();j++){
                if(str[j] == s[j]){
                    count++;
                }
                else{
                    break;
                }
            }
            
        }
        return count;
    }