n devices, each with its own number from 1 to 10⁵. It is wired as a star: one device is the hub, and every other device has a single cable running to it. There are n - 1 cables in total.
You are given the list of cables links, where links[i] = [a, b] means devices a and b are connected. Cables, and the two ends of each cable, come in no particular order. Return the number of the hub.links=[[3, 1], [2, 3], [3, 4]] → 3
Node 3 appears in all three links, so it is the hub.
links=[[5, 2], [1, 2], [2, 4], [3, 2]] → 2
Every link goes through node 2.
links=[[3, 1], [2, 3], [3, 4]]
3
Run checks the first 3 tests in your browser. Submit checks all 50 tests on the server, hidden ones included.