@@ -0,0 +1,1568 @@
+package problems;%0A%0Aimport java.util.Arrays;%0A%0A/**%0A * Leetcode: Longest Increasing Path%0A * Created by alan on 2/23/2016.%0A */%0Apublic class LongestIncreasingPath %7B%0A    public int longestIncreasingPath(int%5B%5D%5B%5D matrix) %7B%0A        if (matrix.length == 0 %7C%7C matrix%5B0%5D.length == 0)%0A            return 0;%0A        int m = matrix.length, n = matrix%5B0%5D.length;%0A        int%5B%5D%5B%5D count = new int%5Bm%5D%5Bn%5D;%0A%0A        int max = 0;%0A        for (int i = 0; i %3C m; i++) %7B%0A            for (int j = 0; j %3C n; j++) %7B%0A                if (count%5Bi%5D%5Bj%5D == 0)%0A                    findLongest(matrix, i, j, count);%0A                max = Math.max(max, count%5Bi%5D%5Bj%5D);%0A            %7D%0A        %7D%0A        return max;%0A    %7D%0A%0A    public void findLongest(int%5B%5D%5B%5D matrix, int x, int y, int%5B%5D%5B%5D count) %7B%0A        int m = matrix.length, n = matrix%5B0%5D.length;%0A        int%5B%5D%5B%5D diff = %7B%7B-1, 0%7D, %7B1, 0%7D, %7B0, -1%7D, %7B0, 1%7D%7D;%0A        int longest = 1;%0A%0A        for (int%5B%5D dif : diff) %7B%0A            int x1 = x + dif%5B0%5D, y1 = y + dif%5B1%5D;%0A            if (x1 %3E= 0 && x1 %3C m && y1 %3E= 0 && y1 %3C n && matrix%5Bx%5D%5By%5D %3C matrix%5Bx1%5D%5By1%5D) %7B%0A                if (count%5Bx1%5D%5By1%5D == 0)%0A                    findLongest(matrix, x1, y1, count);%0A                longest = Math.max(longest, count%5Bx1%5D%5By1%5D + 1);%0A            %7D%0A        %7D%0A        count%5Bx%5D%5By%5D = longest;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        LongestIncreasingPath lp = new LongestIncreasingPath();%0A        int%5B%5D%5B%5D matrix = %7B%7B3, 4, 5%7D, %7B3, 2, 6%7D, %7B2, 2, 1%7D%7D;%0A%0A        System.out.println(Arrays.deepToString(matrix) + %22 : %22 + lp.longestIncreasingPath(matrix));%0A    %7D%0A%7D%0A

Add Longest Increasing Path