Easy java solution, why wrong?


  • 0
    public class Solution {
        public boolean repeatedSubstringPattern(String str) {
            if(str.length() < 2)
                return true;
            String cur = "";
            for(int i = 0; i <  str.length(); i++){
                cur += str.charAt(i);
                if(str.length() % cur.length() == 0){
                    int n = str.length() / cur.length();
                    String temp = "";
                    for(int j = 1; j <= n; j++)
                        temp += cur;
                    if(temp == str)
                        return true;
                }
            }
            return false;
        }
    }
    

Log in to reply
 

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