We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent eeb3a55 commit aa4d846Copy full SHA for aa4d846
1 file changed
live10/test101/문제3/황장현.js
@@ -0,0 +1,36 @@
1
+function solution(n, edge) {
2
+ const connects = new Array(n).fill().map((_) => []);
3
+ for (const e of edge) {
4
+ connects[e[0] - 1].push(e[1] - 1);
5
+ connects[e[1] - 1].push(e[0] - 1);
6
+ }
7
+
8
+ const visited = [1];
9
+ const queue = [0];
10
+ while (queue.length) {
11
+ const cur = queue.shift();
12
13
+ for (const next of connects[cur]) {
14
+ if (!visited[next]) {
15
+ visited[next] = visited[cur] + 1;
16
+ queue.push(next);
17
18
19
20
21
+ const max = Math.max(...visited);
22
23
+ return visited.filter((el) => el === max).length;
24
+}
25
26
+console.log(
27
+ solution(6, [
28
+ [3, 6],
29
+ [4, 3],
30
+ [3, 2],
31
+ [1, 3],
32
+ [1, 2],
33
+ [2, 4],
34
+ [5, 2],
35
+ ])
36
+);
0 commit comments