File tree 1 file changed +7
-6
lines changed
scripts/algorithms/W/Word Ladder II
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 23 ms (Top 90.82%) | Memory: 9.9 MB (Top 40.33%)
1
2
class Solution {
2
3
public:
3
4
map<string,vector<string>> parent;
@@ -24,12 +25,12 @@ class Solution {
24
25
child[pos]=c;
25
26
if (dist.count (child)) {
26
27
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
30
31
q.push (child);
31
32
}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
33
34
}
34
35
}
35
36
}
@@ -43,7 +44,7 @@ class Solution {
43
44
}
44
45
void pathfinder (string par,vector<string>&path) {
45
46
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
47
48
return ;
48
49
}
49
50
for (string node : parent[par]) {
@@ -52,4 +53,4 @@ class Solution {
52
53
path.pop_back ();
53
54
}
54
55
}
55
- };
56
+ };
You can’t perform that action at this time.
0 commit comments