题解 | #微信红包#
微信红包
https://www.nowcoder.com/practice/fbcf95ed620f42a88be24eb2cd57ec54
hashmap遍历
import java.util.*;
public class Gift {
public int getValue(int[] gifts, int n) {
// write code here
Map<Integer,Integer> countMap=new HashMap<>();
for(int gift:gifts){
int count=countMap.getOrDefault(gift,0);
if(count+1>n/2){
return gift;
}
countMap.put(gift,countMap.getOrDefault(gift,0)+1);
}
return 0;
}
}
顺丰集团工作强度 322人发布