c++ 7-line solution


  • 0
    H
    class Solution {
    public:
        bool repeatedSubstringPattern(string str) {
            for(int len = str.size() / 2; len >= 1; len --) 
                if(str.size() % len == 0) {
                    string tmp = "";
                    for(int i = 0; i < str.size() / len; i ++) tmp += str.substr(0, len);
                    if(tmp == str) return true;
                }
            return false;
        }
    };
    

  • 0
    Y

    @H41 The code looks good, but it got 'Time Limit Exceeded'


  • 0
    H

    @yyoo79 Sorry I don't know what's the problem neither, but I tried my code just now and still got AC.


Log in to reply
 

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