@@ -0,0 +1,1352 @@
+/**%0A * Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).%0A **/%0A%0Apublic class NumMatrix %7B%0A    private int%5B%5D%5B%5D sum; // sum%5Bi%5D%5Bj%5D is the sum from nums%5B0%5D%5B0%5D to nums%5Bi+1%5D%5Bj+1%5D%0A    %0A    public NumMatrix(int%5B%5D%5B%5D matrix) %7B%0A%09%09if(matrix == null %7C%7C matrix.length == 0 %7C%7C matrix%5B0%5D.length == 0)%0A%09%09%09return;%0A%0A%09%09int row = matrix.length;%0A%09%09int col = matrix%5B0%5D.length;%0A%0A        sum = new int%5Brow+1%5D%5Bcol+1%5D;%0A%09%09for(int r = 1; r %3C= row; r++)%0A%09%09%09for(int c = 1; c %3C= col; c++)%0A%09%09%09%09sum%5Br%5D%5Bc%5D = sum%5Br%5D%5Bc-1%5D + sum%5Br-1%5D%5Bc%5D - sum%5Br-1%5D%5Bc-1%5D + matrix%5Br-1%5D%5Bc-1%5D;%0A    %7D%0A%0A    public int sumRegion(int row1, int col1, int row2, int col2) %7B%0A        return sum%5Brow2+1%5D%5Bcol2+1%5D - sum%5Brow1%5D%5Bcol2+1%5D - sum%5Brow2+1%5D%5Bcol1%5D + sum%5Brow1%5D%5Bcol1%5D;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        int%5B%5D%5B%5D aMatrix = %7B%0A%09        %7B3, 0, 1, 4, 2%7D,%0A  %09        %7B5, 6, 3, 2, 1%7D,%0A  %09        %7B1, 2, 0, 1, 5%7D,%0A          %09%7B4, 1, 0, 1, 7%7D,%0A          %09%7B1, 0, 3, 0, 5%7D%0A            %7D;%0A        NumMatrix nm = new NumMatrix(aMatrix);%0A        System.out.println(nm.sumRegion(0,0,0,0));%0A        System.out.println(nm.sumRegion(0,0,0,1));%0A        System.out.println(nm.sumRegion(2,1,4,3));%0A        System.out.println(nm.sumRegion(1,1,2,2));%0A        System.out.println(nm.sumRegion(1,2,2,4));%0A    %7D%0A%7D%0A

Create 304.java