Advertisement
Guest User

Untitled

a guest
May 4th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. public Long getMode() {
  2.  
  3.  
  4. long repeatCount = 0;
  5. long previousRepCnt = 0;
  6.  
  7. for (int i = 0; i < length; i++) {
  8. int count = 0;
  9.  
  10. for (int j = 0; j < length; j++) {
  11.  
  12. if (this.elements[i] == this.elements[j]) {
  13. count++;
  14. }
  15. }
  16.  
  17. if (count > previousRepCnt) {
  18. previousRepCnt = count;
  19. repeatCount = this.elements[i];
  20. mode = repeatCount;
  21.  
  22. }
  23.  
  24. if (repeatCount == previousRepCnt){
  25. mode = (long)-1;
  26. }
  27.  
  28. repeatCount = 0;
  29. }
  30. return this.mode;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement