Simple DP solution
public int maxEnvelopes(int[][] envelopes) {\n        if (   envelopes           == null\n            || envelopes.length    == 0\n            || envelopes[0]  
    public int maxEnvelopes(int[][] envelopes) {\n        if (   envelopes           == null\n            || envelopes.length    == 0\n            || envelopes[0]        == null\n            || envelopes[0].length == 0){\n            return 0;    \n        }\n        \n        Arrays.sort(envelopes, new Comparator<int[]>(){\n            @Override\n            public int compare(int[] e1, int[] e2){\n                return Integer.compare(e1[0], e2[0]);\n            }\n        });\n        \n        int   n  = envelopes.length;\n        int[] dp = new int[n];\n        \n        int ret = 0;\n        for (int i = 0; i < n; i++){\n            dp[i] = 1;\n            \n            for (int j = 0; j < i; j++){\n                if (   envelopes[i][0] > envelopes[j][0]\n                    && envelopes[i][1] > envelopes[j][1]){\n                    dp[i] = Math.max(dp[i], 1 + dp[j]);    \n                }\n            }\n            \n            ret = Math.max(ret, dp[i]);\n        }\n        return ret;\n    }
[]