title: Find a Repeated Substring Pattern in a given string
body: <p>Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.</p>
  
  <p>Example 1:
  Input: "abab"</p>
  
  <p>Output: True</p>
  
  <p>Explanation: It's the substring "ab" twice.
  Example 2:
  Input: "aba"</p>
  
  <p>Output: False
  Example 3:
  Input: "abcabcabcabc"</p>
  
  <p>Output: True</p>
  
  <p>Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)</p>
  
  <p>I found the above question on a online programming site <a href="https://leetcode.com/problems/repeated-substring-pattern/" rel="nofollow noreferrer">here</a>. I submitted the following answer which is working for the custom test cases, but is getting time exceed exception on submission. I tried other way of regex pattern matching, but as expected, that should be taking more time than this way, and fails too.</p>
  
  <pre><code>public class Solution {
      public boolean repeatedSubstringPattern(String str) {
          int substringEndIndex = -1;
          int i = 0;
          char startOfString = str.charAt(0);
          i++;
          char ch;
          while(i &lt; str.length()){
              if((ch=str.charAt(i)) != startOfString){
                  //create a substring until the char at start of string is encountered 
                  i++;
              }else{
                  if(str.split(str.substring(0,i)).length == 0){
                      return true;
                  }else{
                      //false alarm. continue matching.
                      i++;
                  }
              }
          }
          return false;
      }
  }
  </code></pre>
  
  <p>Any idea on where I am taking too much time.</p>