반응형
https://leetcode.com/problems/find-center-of-star-graph
center node는 모든 edge에 나와야하므로, 임의의 두개의 노드만 검사해줘도 됩니다.
class Solution {
public:
int findCenter(vector<vector<int>>& edges) {
return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] ?
edges[0][0] : edges[0][1];
}
};
반응형
'기록' 카테고리의 다른 글
LeetCode 2058. Find the Minimum and Maximum Number of Nodes Between Critical Points (0) | 2024.07.06 |
---|---|
LeetCode 2285. Maximum Total Importance of Roads (0) | 2024.06.30 |
LeetCode 2192. All Ancestors of a Node in a Directed Acyclic Graph (0) | 2024.06.29 |
LeetCode 1051. Height Checker (0) | 2024.06.23 |
LeetCode 945. Minimum Increment to Make Array Unique (0) | 2024.06.15 |