title: Reduce number of calls of function
body: <p>I'm writing a program for a unimodal search to find the maximum of a row of numbers via <code>compareTo</code> and <code>Comparator</code>. </p>
  
  <p>I've written the code and technically it should be alright. However, the runtime is too high. It should be smaller or equal to 28. </p>
  
  <p>A tip was to create a variable so the function isn't called over and over again to reduce the runtime. But I'm having difficulties to do that. Can someone help? Here's my code.</p>
  
  <pre><code>import java.util.Comparator;
  
  public class UnimodaleSuche {
      public static &lt;T extends Comparable&lt;T&gt;&gt; T suche (UnimodaleListe &lt;T&gt; Liste, int s, int e){
          if (s == e){
              return Liste.hole(e);   
          } else if(s+1 == e){
              if (Liste.hole(s).compareTo(Liste.hole(e)) &lt; 0) {
                  return Liste.hole(e);
              } else {
                  return Liste.hole(s);
              }
          }
  
          int m = (s+e)/2;
          Liste.hole (m).compareTo(Liste.hole(m+1));
          if (Liste.hole (m).compareTo(Liste.hole(m+1)) &lt; 0){
              return suche(Liste, m+1, e);
          }else{
              return suche(Liste, s, m);
          }
      }
  
      public static &lt;T&gt; T suche (UnimodaleListe &lt;T&gt; Liste, int s, int e, Comparator &lt;T&gt; c) {
          if (s == e) {
              return Liste.hole(e);   
          } else if(s+1 == e){
              if (c.compare(Liste.hole(s), Liste.hole(e)) &lt; 0) {
                  return Liste.hole(e);
              } else {
                  return Liste.hole(s);
              }
          }
  
          int m = (s+e)/2;
          c.compare(Liste.hole(m), Liste.hole(m+1));
          if (c.compare(Liste.hole(s), Liste.hole(e)) &lt; 0) {
              return suche(Liste, m+1, e,c);
          }else{
              return suche(Liste, s, m, c);
          }
      }
  }
  </code></pre>