Skip to content

Commit c082e94

Browse files
committed
Runtime: 23 ms (Top 90.82%) | Memory: 9.9 MB (Top 40.33%)
1 parent ed8904b commit c082e94

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/algorithms/W/Word Ladder II/Word Ladder II.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 23 ms (Top 90.82%) | Memory: 9.9 MB (Top 40.33%)
12
class Solution {
23
public:
34
map<string,vector<string>> parent;
@@ -24,12 +25,12 @@ class Solution {
2425
child[pos]=c;
2526
if(dist.count(child)) {
2627
if(dist[child] > 1 + dist[par]) {
27-
dist[child] = 1 + dist[par];
28-
parent[child].clear(); // remove all parents , a better parent exists (shorter path from src to child)
29-
parent[child].push_back(par); // add that parent
28+
dist[child] = 1 + dist[par];
29+
parent[child].clear(); // remove all parents , a better parent exists (shorter path from src to child)
30+
parent[child].push_back(par); // add that parent
3031
q.push(child);
3132
}else if(dist[child] == 1 + dist[par]) {
32-
parent[child].push_back(par); // add all parents of the best current distance
33+
parent[child].push_back(par); // add all parents of the best current distance
3334
}
3435
}
3536
}
@@ -43,7 +44,7 @@ class Solution {
4344
}
4445
void pathfinder(string par,vector<string>&path) {
4546
if(par=="root") {
46-
ans.push_back(path); // no parent exists of the root node , add the path to answer
47+
ans.push_back(path); // no parent exists of the root node , add the path to answer
4748
return;
4849
}
4950
for(string node : parent[par]) {
@@ -52,4 +53,4 @@ class Solution {
5253
path.pop_back();
5354
}
5455
}
55-
};
56+
};

0 commit comments

Comments
 (0)