Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Long getMode() {
- long repeatCount = 0;
- long previousRepCnt = 0;
- for (int i = 0; i < length; i++) {
- int count = 0;
- for (int j = 0; j < length; j++) {
- if (this.elements[i] == this.elements[j]) {
- count++;
- }
- }
- if (count > previousRepCnt) {
- previousRepCnt = count;
- repeatCount = this.elements[i];
- mode = repeatCount;
- }
- if (repeatCount == previousRepCnt){
- mode = (long)-1;
- }
- repeatCount = 0;
- }
- return this.mode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement