Class Solution

java.lang.Object
g0301_0400.s0354_russian_doll_envelopes.Solution

public class Solution extends Object
354 - Russian Doll Envelopes.<p>Hard</p> <p>You are given a 2D array of integers <code>envelopes</code> where <code>envelopes[i] = [w<sub>i</sub>, h<sub>i</sub>]</code> represents the width and the height of an envelope.</p> <p>One envelope can fit into another if and only if both the width and height of one envelope are greater than the other envelope&rsquo;s width and height.</p> <p>Return <em>the maximum number of envelopes you can Russian doll (i.e., put one inside the other)</em>.</p> <p><strong>Note:</strong> You cannot rotate an envelope.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> envelopes = [[5,4],[6,4],[6,7],[2,3]]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The maximum number of envelopes you can Russian doll is <code>3</code> ([2,3] => [5,4] => [6,7]).</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> envelopes = [[1,1],[1,1],[1,1]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= envelopes.length <= 5000</code></li> <li><code>envelopes[i].length == 2</code></li> <li><code>1 <= w<sub>i</sub>, h<sub>i</sub> <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxEnvelopes

      public int maxEnvelopes(int[][] envelopes)