Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int maxOccurrences(List<Integer> list) {
- if(list.isEmpty()) {
- return 0;
- } else {
- Map<Integer, Integer> m = new HashMap<Integer,Integer>();
- Iterator<Integer> it = list.iterator();
- int max = 0;
- while( it.hasNext() ) {
- int next = it.next();
- int val = 0;
- if( m.containsKey(next) ) {
- int value = m.get(next)+1;
- m.put(next, value);
- val = value;
- } else {
- m.put(next, 1);
- val = 1;
- }
- if( val>max ) {
- max = val;
- }
- }
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement