File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 257
257
1716|[ Calculate Money in Leetcode Bank] ( ./1716-calculate-money-in-leetcode-bank.js ) |Easy|
258
258
1748|[ Sum of Unique Elements] ( ./1748-sum-of-unique-elements.js ) |Easy|
259
259
1780|[ Check if Number is a Sum of Powers of Three] ( ./1780-check-if-number-is-a-sum-of-powers-of-three.js ) |Medium|
260
+ 1791|[ Find Center of Star Graph] ( ./1791-find-center-of-star-graph.js ) |Easy|
260
261
1832|[ Check if the Sentence Is Pangram] ( ./1832-check-if-the-sentence-is-pangram.js ) |Easy|
261
262
1880|[ Check if Word Equals Summation of Two Words] ( ./1880-check-if-word-equals-summation-of-two-words.js ) |Easy|
262
263
1886|[ Determine Whether Matrix Can Be Obtained By Rotation] ( ./1886-determine-whether-matrix-can-be-obtained-by-rotation.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1791. Find Center of Star Graph
3
+ * https://leetcode.com/problems/find-center-of-star-graph/
4
+ * Difficulty: Easy
5
+ *
6
+ * There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a
7
+ * graph where there is one center node and exactly n - 1 edges that connect the center node with
8
+ * every other node.
9
+ *
10
+ * You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an
11
+ * edge between the nodes ui and vi. Return the center of the given star graph.
12
+ */
13
+
14
+ /**
15
+ * @param {number[][] } edges
16
+ * @return {number }
17
+ */
18
+ var findCenter = function ( edges ) {
19
+ const set = new Set ( ) ;
20
+ for ( const edge of edges ) {
21
+ for ( const node of edge ) {
22
+ if ( set . has ( node ) ) {
23
+ return node ;
24
+ }
25
+ set . add ( node ) ;
26
+ }
27
+ }
28
+ } ;
You can’t perform that action at this time.
0 commit comments