Java 8-liner using TreeSet
\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        Arrays.sort(envelopes, (a, b)-> a[0]==b[0]? b[1]-a[1]: a[0]-b[0]);\n        TreeSe
```\nclass Solution {\n    public int maxEnvelopes(int[][] envelopes) {\n        Arrays.sort(envelopes, (a, b)-> a[0]==b[0]? b[1]-a[1]: a[0]-b[0]);\n        TreeSet<Integer> sortedSet = new TreeSet<>();\n        for (int[] env : envelopes) {\n            Integer ceiling = sortedSet.ceiling(env[1]);            \n            if (ceiling != null && ceiling.intValue() != env[1]) sortedSet.remove(ceiling);\n            sortedSet.add(env[1]);\n        }        \n        return sortedSet.size();\n    }\n}\n```
[]