要输出1出现两次0出现一次
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class T {
public static void main(String[] args) {
System.out.println(t1(new ArrayList(3) {{
add(1);
add(1);
add(3);
add(4);
add(3);
add(3);
add(3);
}}));
}
public static Map<Integer,Integer> t1( List<Integer> items ) {
if (items == null || items.size() == 0) return null;
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Integer temp : items) {
Integer count = map.get(temp);
map.put(temp, (count == null) ? 1 : count + 1);
}
return map;
}
}
望采纳