Find the mode in array : <p>This code can only get the mode when single mode exist. I want to know how to return -1 when 2 modes exist. For example : 1 1 1 2 2 2 3. And return -1 when no mode exist, 1 2 3 4 5 6.</p>

<pre><code> public Long getMode() {


      long [] num = this.getElements();

      long maxValue=0, maxCount=0; 
      for (int i = 0; i &lt; num.length; ++i){
          long count = 0;
          for (int j = 0; j &lt; num.length; ++j){
              if (num[j] == num[i])
              ++count;
            }
             if (count &gt; maxCount){
              maxCount = count;
              maxValue = num[i];
           }
        }
         return maxValue;
      } 
</code></pre>
