62,634
社区成员




private static class Counter {
private int cnt;
public Counter inc() {
cnt++;
return this;
}
public int value() {
return cnt;
}
public String toString() {
return String.valueOf(cnt);
}
}
Map<Integer, Counter> mapCounter = new HashMap<Integer, Counter>();
for (int i = 0; i < a.length; i++) {
Counter cnt = mapCounter.get(a[i]);
if (cnt == null) {
cnt = new Counter();
mapCounter.put(words[i], cnt.inc());
} else {
cnt.inc();
if (cnt.value() >= a.length / 2) break; // 找到了
}
}