Short Java Solution


  • 1
    B
        public boolean repeatedSubstringPattern(String str) {
            StringBuilder sb = new StringBuilder();
            sb.append(str);
            sb.append(str);
            String check = sb.substring(1,sb.length() - 1);
            return check.contains(str);
        }
    

  • 0
    N

    Just for fun, you can implement it with one line. LOL

    public boolean repeatedSubstringPattern(String str) {
        return new StringBuilder().append(str).append(str).substring(1,str.length() - 1).contains(str);
    }
    

Log in to reply
 

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