feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
This commit is contained in:
committed by
GitHub
parent
0095583028
commit
ee1e8abd87
@ -3,6 +3,7 @@ id: 587d825d367417b2b2512c96
|
||||
title: 深度优先搜索
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
dashedName: depth-first-search
|
||||
---
|
||||
|
||||
# --description--
|
||||
@ -151,5 +152,45 @@ assert(
|
||||
);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
function dfs(graph, root) {
|
||||
|
||||
}
|
||||
|
||||
var exDFSGraph = [
|
||||
[0, 1, 0, 0],
|
||||
[1, 0, 1, 0],
|
||||
[0, 1, 0, 1],
|
||||
[0, 0, 1, 0]
|
||||
];
|
||||
console.log(dfs(exDFSGraph, 3));
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function dfs(graph, root) {
|
||||
var stack = [];
|
||||
var tempV;
|
||||
var visited = [];
|
||||
var tempVNeighbors = [];
|
||||
stack.push(root);
|
||||
while (stack.length > 0) {
|
||||
tempV = stack.pop();
|
||||
if (visited.indexOf(tempV) == -1) {
|
||||
visited.push(tempV);
|
||||
tempVNeighbors = graph[tempV];
|
||||
for (var i = 0; i < tempVNeighbors.length; i++) {
|
||||
if (tempVNeighbors[i] == 1) {
|
||||
stack.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return visited;
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user