java.lang.Object
g1501_1600.s1584_min_cost_to_connect_all_points.Solution

public class Solution extends Object
1584 - Min Cost to Connect All Points.<p>Medium</p> <p>You are given an array <code>points</code> representing integer coordinates of some points on a 2D-plane, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p> <p>The cost of connecting two points <code>[x<sub>i</sub>, y<sub>i</sub>]</code> and <code>[x<sub>j</sub>, y<sub>j</sub>]</code> is the <strong>manhattan distance</strong> between them: <code>|x<sub>i</sub> - x<sub>j</sub>| + |y<sub>i</sub> - y<sub>j</sub>|</code>, where <code>|val|</code> denotes the absolute value of <code>val</code>.</p> <p>Return <em>the minimum cost to make all points connected.</em> All points are connected if there is <strong>exactly one</strong> simple path between any two points.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/08/26/d.png" alt="" /></p> <p><strong>Input:</strong> points = [[0,0],[2,2],[3,10],[5,2],[7,0]]</p> <p><strong>Output:</strong> 20</p> <p><strong>Explanation:</strong> <img src="https://assets.leetcode.com/uploads/2020/08/26/c.png" alt="" /></p> <p>We can connect the points as shown above to get the minimum cost of 20.</p> <p>Notice that there is a unique path between every pair of points.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> points = [[3,12],[-2,5],[-4,1]]</p> <p><strong>Output:</strong> 18</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= points.length <= 1000</code></li> <li><code>-10<sup>6</sup> <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>6</sup></code></li> <li>All pairs <code>(x<sub>i</sub>, y<sub>i</sub>)</code> are distinct.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minCostConnectPoints

      public int minCostConnectPoints(int[][] points)
    • constructMST

      public void constructMST(int[] parent, int[][] points, boolean[] mst, PriorityQueue<g1501_1600.s1584_min_cost_to_connect_all_points.Solution.Pair> pq, int[] dist)
    • containsFalse

      public boolean containsFalse(boolean[] mst)
    • getDistance

      public int getDistance(int[] p1, int[] p2)