Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lab03/src/adventure/BeeCountingStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdRandom;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -11,7 +12,7 @@ public class BeeCountingStage implements AdventureStage {

private final In in;
private final Map<String, AdventureStage> responses;
private List<String> input;
private final List<String> input = new ArrayList<>();

public BeeCountingStage(In in) {
this.in = in;
Expand Down Expand Up @@ -83,7 +84,7 @@ public Map<String, AdventureStage> getResponses() {
*/
private int sumInput() {
int sum = 0;
for (int i = 0; i <= this.input.size(); i++) {
for (int i = 0; i <= this.input.size() - 1; i++) {
sum += Integer.parseInt(this.input.get(i));
}
return sum;
Expand Down
6 changes: 3 additions & 3 deletions lab03/src/adventure/PalindromeStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Map<String, AdventureStage> getResponses() {
/** Returns a new IntList with the contents of the original IntList in reverse order.*/
private static IntList reverseList(IntList l) {
IntList reversed = null;
while (l.rest != null) {
while (l != null) {
reversed = new IntList(l.first, reversed);
l = l.rest;
}
Expand All @@ -77,8 +77,8 @@ private static IntList reverseList(IntList l) {
*/
private static IntList digitsToIntList(String s) {
int[] a = new int[s.length()];
for (int i = s.length(); i > 0; i++) {
a[s.length() - i] = Character.getNumericValue(s.charAt(i));
for (int i = 0; i < s.length(); i++) {
a[i] = Character.getNumericValue(s.charAt(i));
}
return IntList.of(a);
}
Expand Down
3 changes: 2 additions & 1 deletion lab03/src/adventure/SpeciesListStage.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static int arraySimilarity(List<String> listOne, List<String> listTwo) {
copy.remove(o);
}
}
return similarObjects / listOne.size();
if (similarObjects == listOne.size()) return 1;
return 0;
}
}