https://leetcode.com/problems/minimum-operations-to-make-a-uni-value-grid/
    考察一个数学知识,如何找到距离所有点之和距离最近的点


    1. use std::collections::HashMap;
    2. use std::cmp;
    3. impl Solution {
    4. pub fn min_operations(grid: Vec<Vec<i32>>, x: i32) -> i32 {
    5. let mut arr: Vec<i32> = grid.iter().flatten().cloned().collect();
    6. arr.sort();
    7. let mid = arr[(arr.len() - 1) / 2];
    8. let mut res = 0;
    9. for &y in arr.iter() {
    10. if y == mid {
    11. continue;
    12. }
    13. let diff = (y - mid).abs();
    14. if diff % x != 0 {
    15. return -1;
    16. }
    17. res += diff / x;
    18. }
    19. res
    20. }
    21. }

    https://asvrada.github.io/blog/median-shortest-distance-sum/
    记住结论,一维空间,距离所有点最近的点,就是最中间那个点
    其实就是让两边一样多,最中间的两个之间的数(含)都可以,这样移动到这个点的代价最小

    另外,Rust刷题比较难受,效率也比较着迷,试着熟悉上手吧,不能被Python惯坏了。