@@ -0,0 +1,1079 @@
+package leetcode;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Comparator;%0A%0A/**%0A * https://leetcode.com/problems/matrix-cells-in-distance-order/%0A */%0Apublic class Problem1030 %7B%0A    public int%5B%5D%5B%5D allCellsDistOrder(int R, int C, int r0, int c0) %7B%0A        Dist%5B%5D dists = new Dist%5BR * C%5D;%0A        int index = 0;%0A        for (int r = 0; r %3C R; r++) %7B%0A            for (int c = 0; c %3C C; c++) %7B%0A                int dist = Math.abs(r0 - r) + Math.abs(c0 - c);%0A                dists%5Bindex++%5D = new Dist(r, c, dist);%0A            %7D%0A        %7D%0A        Arrays.sort(dists, Comparator.comparingInt(a -%3E a.dist));%0A        int%5B%5D%5B%5D answer = new int%5Bdists.length%5D%5B2%5D;%0A        for (int i = 0; i %3C dists.length; i++) %7B%0A            answer%5Bi%5D = new int%5B%5D%7Bdists%5Bi%5D.row, dists%5Bi%5D.col%7D;%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static class Dist %7B%0A        private final int row;%0A        private final int col;%0A        private final int dist;%0A%0A        public Dist(int row, int col, int dist) %7B%0A            this.row = row;%0A            this.col = col;%0A            this.dist = dist;%0A        %7D%0A    %7D%0A%7D%0A

Solve problem 1030