-
[leetcode] 1791. Find Center of Star Graph카테고리 없음 2021. 3. 20. 12:04728x90
class Solution { public: int findCenter(vector<vector<int>>& edges) { int a1 = edges[0][0]; int a2 = edges[0][1]; int b1 = edges[1][0]; int b2 = edges[1][1]; if(a1 == b1 || a1 == b2) return a1; else return a2; } };
출제의도는 각 엣지로 인접 노드들을 Map이나 Set으로 체크해서 중복된 노드를 리턴하는 것으로 보이나,,
위와 같이 아무생각없이 풀어도 잘 풀린다.
시간복잡도 : O(1)