commit 6128ad82317afb3aaea8a7882b2c598b9ec340af parent 0036fa24a145507281f9dc41620bda9b137ce2df Author: AndrewLockVI <andrewlaack1@gmail.com> Date: Thu, 11 May 2023 13:53:13 -0500 Completed find center of star graph Diffstat:
| A | find-center-of-star-graph/find-center-of-star-graph.dart | | | 16 | ++++++++++++++++ |
1 file changed, 16 insertions(+), 0 deletions(-)
diff --git a/find-center-of-star-graph/find-center-of-star-graph.dart b/find-center-of-star-graph/find-center-of-star-graph.dart @@ -0,0 +1,16 @@ +//Given a list of edges all of which are connected to the center +//return the value at the center. +//The time complexity of my code is O(1). +//Time: 384ms Beats: 60% +//Memory: 213MB Beats: 60% +class Solution { + int findCenter(List<List<int>> edges) { + + int opt1 = edges[0][0]; + int opt2 = edges[0][1]; + if(opt1 == edges[1][0] || opt1 == edges[1][1] ){ + return opt1; + } + return opt2; + } +}