Skip to content

Commit 8154859

Browse files
add 1791
1 parent 69658eb commit 8154859

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1791|[Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1791.java) ||Medium|Graph|
1112
|1785|[Minimum Elements to Add to Form a Given Sum](https://leetcode.com/problems/minimum-elements-to-add-to-form-a-given-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1785.java) ||Medium|Greedy|
1213
|1784|[Check if Binary String Has at Most One Segment of Ones](https://leetcode.com/problems/check-if-binary-string-has-at-most-one-segment-of-ones/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1784.java) ||Easy|Greedy|
1314
|1781|[Sum of Beauty of All Substrings](https://leetcode.com/problems/sum-of-beauty-of-all-substrings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1781.java) ||Medium|HashTable, String|
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1791 {
4+
public static class Solution1 {
5+
public int findCenter(int[][] edges) {
6+
int[] neighbors = new int[edges.length + 1];
7+
for (int[] edge : edges) {
8+
int a = edge[0];
9+
int b = edge[1];
10+
neighbors[a - 1]++;
11+
neighbors[b - 1]++;
12+
}
13+
for (int i = 0; i < neighbors.length; i++) {
14+
if (neighbors[i] == edges.length) {
15+
return i + 1;
16+
}
17+
}
18+
return -1;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)