SHARE
TWEET

Untitled

advictoriam Jan 23rd, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Numbers
  2. {
  3.    /**
  4.       Computes the length of the longest sequence that occurs in the
  5.       start of the left half and the end of the right half of an
  6.       array.
  7.       @param values an array of integer values
  8.       @return the length of the longest end sequence
  9.    */
  10.    public int sameEnds(int[] values)
  11.    {
  12.       int length = 0;
  13.       int firstIndex = 0;
  14.       for(int i = (int)((double)values.length / 2 +.5); i < values.length; i++)
  15.       {
  16.          for(int j = i; j < values.length; j++)
  17.          {
  18.             if(values[firstIndex] == values[j])
  19.             {
  20.                length++;
  21.                if(j + 1 == values.length){return length;}
  22.                firstIndex++;
  23.             }
  24.             else{break;}
  25.          }
  26.          length = 0;
  27.          firstIndex = 0;
  28.       }
  29.       return 0;
  30.    }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top