-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathFindResult.java
More file actions
53 lines (43 loc) · 1.33 KB
/
FindResult.java
File metadata and controls
53 lines (43 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ladder2;
import java.util.ArrayList;
import java.util.List;
public class FindResult {
private List<Ladder2> completeLadder;
private int location;
private List<Integer> allList;
public FindResult(List<Ladder2> completeLadder, int location) {
this.completeLadder = completeLadder;
this.location = location;
this.allList = new ArrayList<>();
}
public void setLocation(int l) {
this.location = l;
}
public int move(int i, List<String> line) {
// Check if we can move to the left
if (i > 0 && line.get(i - 1).equals("-----")) {
return i - 1;
}
// Check if we can move to the right
if (i < line.size() - 1 && line.get(i).equals("-----")) {
return i + 1;
}
// Otherwise stay in the same position
return i;
}
public int find() {
int currentPosition = location;
for (Ladder2 ladder : completeLadder) {
currentPosition = move(currentPosition, ladder.getLadder());
}
return currentPosition;
}
public List<Integer> findAll(int n) {
allList.clear(); // 이전 결과를 지우기 위해 초기화
for (int i = 0; i < n; i++) {
setLocation(i);
allList.add(find());
}
return allList;
}
}