3 日,20 小时
Questions & Answers
29
public class HashMap
{
//need to add some code here but I don't know what
private class MyHashMap<K,V> {
MyHashMap() {
}
void put(K key , V value) {
// find solution
}
V get(K key) {
//how to return value from key?
return null;
}
// find solution
}
public void doTestsPass()
{
int [][] testCases = {{1,2},{3,4},{5,6},{1,7},{1,8}};
boolean passed = true;
MyHashMap<Integer,Integer> map = new MyHashMap<>();
for(int [] test: testCases){// find solution
Integer key = test[0];
Integer value = test[1];
map.put(key,value);// find solution
if(!value.equals(map.get(key))){
System.out.println("Test failed["+key+","+value+"]");
//need to find solution
passed = false;
}
}
if(passed) {
// find solution
System.out.println("All tests passed");
}
}
public static void main(String[] Args) {
// find solution
new HashMap().doTestsPass();
}
}
共 (0) 个答案