LeetCode Entry
1791. Find Center of Star Graph
Center of a start graph
1791. Find Center of Star Graph easy
blog post
substack
youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/652
Problem TLDR
Center of a start graph #easy
Intuition
It’s just a common node between two edges.
Approach
Can you make it shorter?
Complexity
-
Time complexity: \(O(1)\)
-
Space complexity: \(O(1)\)
Code
fun findCenter(e: Array<IntArray>) =
e[0].first { it in e[1] }
pub fn find_center(e: Vec<Vec<i32>>) -> i32 {
if e[1].contains(&e[0][0]) { e[0][0] } else { e[0][1] }
}