## 第一大题

### 第一问

```public static int arraySum(int[] arr){
int sum = 0;
for (int elem : arr){
sum += elem;
}
return sum;
}```

### 第二问

```public static int[] rowSums(int[][] arr2D){
int[] sums = new int[arr2D.length];
int rowNum = 0;
for (int[] row : arr2D){
sums[rowNum] = arraySum(row);
rowNum++;
}
return sums;
}```

### 第三问

```public static boolean isDiverse(int[][] arr2D){
int[] sums = rowSums(arr2D);
for (int i = 0; i < sums.length; i++){
for (int j = i + 1; j < sums.length; j++){
if (sums[i] == sums[j]){
return false;
}
}
}
return true;
}```

## 第二大题

```public class HiddenWord
{
private String word;

public HiddenWord(String hWord)
{
word = hWord;
}

public String getHint(String guess){
String hint = "";
for (int i = 0; i < guess.length(); i++){
if (guess.substring(i, i + 1).equals(word.substring(i, i + 1))){
hint += guess.substring(i, i + 1);
} else if (word.indexOf(guess.substring(i, i + 1)) != -1 ){
hint += "+";
} else {
hint += "*";
}
}
return hint;
}
}```

## 第三大题

### 第一问

```public int getValueAt(int row, int col){
for (SparseArrayEntry e : entries){
if (e.getRow() ==  row && e.getCol() == col){
return e.getValue();
}
}
return 0;
}```

### 第二问

```public void removeColumn(int col){
int i = 0;
while (i < entries.size()){
SparseArrayEntry e = entries.get(i);
if (e.getCol() == col){
entries.remove(i);
} else if (e.getCol() > col){
entries.set(i, new SparseArrayEntry(e.getRow(), e.getCol() - 1, e.getValue()));
i++;
} else {
i++;
}
}
numCols--;
}
```

## 第四大题

### 第一问

```public interface NumberGroup
{
boolean contains(int num);
}```

### 第二问

`contains`需要与`interface`定义的一致。注意`Range`未必要实际储存每一个范围内的整数，只要`contains`能正常工作即可。

```public class Range implements NumberGroup
{
private int min;
private int max;

public Range(int min, int max)
{
this.min = min;
this.max = max;
}

public boolean contains(int num) {
return num >= min && num <= max;
}
}```

### 第三问

```public boolean contains(int num){
for (NumberGroup group : groupList){
if (group.contains(num)){
return true;
}
}
return false;
}```