Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. public int[] findTwoHighestDistinctValues(int[] array)
  2. {
  3. int max = Integer.MIN_VALUE;
  4. int secondMax = Integer.MIN_VALUE;
  5.  
  6. for (int value:array)
  7. {
  8. if (value > max)
  9. {
  10. secondMax = max;
  11. max = value;
  12. }
  13. else if (value > secondMax && value < max)
  14. {
  15. secondMax = value;
  16. }
  17. }
  18. return new int[] { max, secondMax };
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement