Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Numbers
- {
- /**
- Computes the length of the longest sequence that occurs in the
- start of the left half and the end of the right half of an
- array.
- @param values an array of integer values
- @return the length of the longest end sequence
- */
- public int sameEnds(int[] values)
- {
- int length = 0;
- int firstIndex = 0;
- for(int i = (int)((double)values.length / 2 +.5); i < values.length; i++)
- {
- for(int j = i; j < values.length; j++)
- {
- if(values[firstIndex] == values[j])
- {
- length++;
- if(j + 1 == values.length){return length;}
- firstIndex++;
- }
- else{break;}
- }
- length = 0;
- firstIndex = 0;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement