|
@@ -42,11 +42,11 @@ class Solution {
|
|
|
queue = newQueue;
|
|
|
for (Integer i : queue) used[i] = true;
|
|
|
}
|
|
|
- dfs(endIdx, new ArrayList<String>());
|
|
|
+ dfs(endIdx, new LinkedList<String>());
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- private void dfs(int idx, List<String> path) {
|
|
|
+ private void dfs(int idx, LinkedList<String> path) {
|
|
|
List<String> newPath = new ArrayList<>();
|
|
|
if (idx == -1) {
|
|
|
newPath.add(beginWord);
|
|
@@ -54,11 +54,11 @@ class Solution {
|
|
|
res.add(newPath);
|
|
|
return;
|
|
|
}
|
|
|
- newPath.add(wordList.get(idx));
|
|
|
- newPath.addAll(path);
|
|
|
+ path.addFirst(wordList.get(idx));
|
|
|
for (Integer i : prev.get(idx)) {
|
|
|
- dfs(i, newPath);
|
|
|
+ dfs(i, path);
|
|
|
}
|
|
|
+ path.pollFirst();
|
|
|
}
|
|
|
|
|
|
private boolean isConvertible(String w1, String w2) {
|