find-center-of-star-graph.dart (422B)
1 //Given a list of edges all of which are connected to the center 2 //return the value at the center. 3 //The time complexity of my code is O(1). 4 //Time: 384ms Beats: 60% 5 //Memory: 213MB Beats: 60% 6 class Solution { 7 int findCenter(List<List<int>> edges) { 8 9 int opt1 = edges[0][0]; 10 int opt2 = edges[0][1]; 11 if(opt1 == edges[1][0] || opt1 == edges[1][1] ){ 12 return opt1; 13 } 14 return opt2; 15 } 16 }