Java solution using hashmap and occurance


#1

Map<Integer, Integer> occurence = new HashMap<Integer, Integer>();

	    	  for(int x: A) {
	    		  int count = 0;
	    		  if(occurence.containsKey(x)) {
	    			  count = occurence.get(x);
	    		  }else {
	    			  count = 1;
	    		  }
	    		  occurence.put(x, count +=1);
	    	  }
	    	
	    	
	    
	    	  Map.Entry<Integer, Integer> maxEntry = null;
	    	  for (Map.Entry<Integer, Integer> entry : occurence.entrySet()) {
	    	        if (maxEntry == null || entry.getValue()
	    	            .compareTo(maxEntry.getValue()) > 0) {
	    	            maxEntry = entry;
	    	        }
	    	    }
	    	    
	    	    return maxEntry.getKey();
}