Java Simple Solution ,easy to understand


  • 0
    4
    public class Solution {
        public boolean repeatedSubstringPattern(String s) {
            for(int i = 0; i < s.length() / 2; i++) {
                if(s.length() % (i + 1) != 0)   continue;
                int j = i + 1;
                while(j < s.length()) {
                    if(s.charAt(j) == s.charAt(j % (i + 1))) {
                        j++;
                        continue;
                    } else {
                        break;
                    }
                }
                if(j >= s.length()) return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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