Class Solution
java.lang.Object
g0601_0700.s0684_redundant_connection.Solution
684 - Redundant Connection.<p>Medium</p>
<p>In this problem, a tree is an <strong>undirected graph</strong> that is connected and has no cycles.</p>
<p>You are given a graph that started as a tree with <code>n</code> nodes labeled from <code>1</code> to <code>n</code>, with one additional edge added. The added edge has two <strong>different</strong> vertices chosen from <code>1</code> to <code>n</code>, and was not an edge that already existed. The graph is represented as an array <code>edges</code> of length <code>n</code> where <code>edges[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that there is an edge between nodes <code>a<sub>i</sub></code> and <code>b<sub>i</sub></code> in the graph.</p>
<p>Return <em>an edge that can be removed so that the resulting graph is a tree of</em> <code>n</code> <em>nodes</em>. If there are multiple answers, return the answer that occurs last in the input.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/05/02/reduntant1-1-graph.jpg" alt="" /></p>
<p><strong>Input:</strong> edges = [[1,2],[1,3],[2,3]]</p>
<p><strong>Output:</strong> [2,3]</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/05/02/reduntant1-2-graph.jpg" alt="" /></p>
<p><strong>Input:</strong> edges = [[1,2],[2,3],[3,4],[1,4],[1,5]]</p>
<p><strong>Output:</strong> [1,4]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == edges.length</code></li>
<li><code>3 <= n <= 1000</code></li>
<li><code>edges[i].length == 2</code></li>
<li><code>1 <= a<sub>i</sub> < b<sub>i</sub> <= edges.length</code></li>
<li><code>a<sub>i</sub> != b<sub>i</sub></code></li>
<li>There are no repeated edges.</li>
<li>The given graph is connected.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findRedundantConnection
public int[] findRedundantConnection(int[][] edges)
-