1584. Min Cost to Connect All Points Medium

@problem@discussion
#Array#Union Find#Minimum Spanning Tree



1/**
2 * [1584] Min Cost to Connect All Points
3 *
4 * You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [xi, yi].
5 * The cost of connecting two points [xi, yi] and [xj, yj] is the manhattan distance between them: |xi - xj| + |yi - yj|, where |val| denotes the absolute value of val.
6 * Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points.
7 *  
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/26/d.png" style="width: 214px; height: 268px;" />
10 * Input: points = [[0,0],[2,2],[3,10],[5,2],[7,0]]
11 * Output: 20
12 * Explanation: 
13 * <img alt="" src="https://assets.leetcode.com/uploads/2020/08/26/c.png" style="width: 214px; height: 268px;" />
14 * We can connect the points as shown above to get the minimum cost of 20.
15 * Notice that there is a unique path between every pair of points.
16 * 
17 * Example 2:
18 * 
19 * Input: points = [[3,12],[-2,5],[-4,1]]
20 * Output: 18
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= points.length <= 1000
26 * 	-10^6 <= xi, yi <= 10^6
27 * 	All pairs (xi, yi) are distinct.
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/min-cost-to-connect-all-points/
33// discuss: https://leetcode.com/problems/min-cost-to-connect-all-points/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn min_cost_connect_points(points: Vec<Vec<i32>>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_1584() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.