title: Converting a string into a palindrome in Java
body: <p>I'm trying to find the shortest palindrome that one can create from S by by adding 0 or more characters in front of it. For example the shortest palindrome can be constructed from 'baaa' is 'aaabaaa'. The two functions that I'm using are given below. This works for this case for doesn't yield the shortest result in all cases. </p>
  
  <pre><code>public static boolean checkPalindrome(String s){
  
          for (int i = 0; i &lt; s.length()/2; i++) {
              if (s.charAt(i) != s.charAt(s.length() - i - 1)) return false;
          }
  
          return true;
  
      }
  
      public static int makePalindrome(String s){
      int min = 0;
      StringBuilder str = new StringBuilder(s);
      for (int i = 1; i &lt; s.length() ; i++) {
          str.insert(0, s.charAt(i));
          if (checkPalindrome(str.toString()) == true) {
              min = str.length();
              break;
          }
  
      }
      return min;
  }
  </code></pre>
  
  <p>I can't seem to figure out what logical step am I missing.</p>