mirror of
				https://git.wolves.top/wolves/leetcode.git
				synced 2025-11-04 17:26:32 +08:00 
			
		
		
		
	250923
This commit is contained in:
		
							
								
								
									
										20
									
								
								25/09/3005.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								25/09/3005.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
class Solution {
 | 
			
		||||
    public int maxFrequencyElements(int[] nums) {
 | 
			
		||||
        Map<Integer, Integer> map = new HashMap<>();
 | 
			
		||||
        int max = 0, ans = 0;
 | 
			
		||||
        for (int num : nums) {
 | 
			
		||||
            map.put(num, map.getOrDefault(num, 0) + 1);
 | 
			
		||||
            int c = map.get(num);
 | 
			
		||||
            if (c > max) {
 | 
			
		||||
                max = c;
 | 
			
		||||
                ans = c;
 | 
			
		||||
            } else if (c == max) {
 | 
			
		||||
                ans += c;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return ans;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user