most repeated int in a 2D array
i am working on a java Method to take in a 2 dimesional array and return
the most repeated Int in the 2D array. if 2 or more numbers are tied for
the most repeating int then the int the appears the least amount of times
in the array will be returned. if the array is empty the method will
return -1. I was reading through some posts and have seen using a Map
mentioned as the best way to accomplish something like this. does anyone
have any ideas were to start i was thinking the below code as a start with
each letter representing a number 0-9 then adding to the value to keep
track of how many times each is encountered.
public static int getMostRepeatedNumber(int[][] array)
{
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
int f = 0;
int g = 0;
int h = 0;
int i = 0;
int j = 0;
}
No comments:
Post a Comment