Class Solution

java.lang.Object
g0401_0500.s0474_ones_and_zeroes.Solution

public class Solution extends Object
474 - Ones and Zeroes.<p>Medium</p> <p>You are given an array of binary strings <code>strs</code> and two integers <code>m</code> and <code>n</code>.</p> <p>Return <em>the size of the largest subset of <code>strs</code> such that there are <strong>at most</strong></em> <code>m</code> <code>0</code><em>&rsquo;s and</em> <code>n</code> <code>1</code><em>&rsquo;s in the subset</em>.</p> <p>A set <code>x</code> is a <strong>subset</strong> of a set <code>y</code> if all elements of <code>x</code> are also elements of <code>y</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;10&rdquo;,&ldquo;0001&rdquo;,&ldquo;111001&rdquo;,&ldquo;1&rdquo;,&ldquo;0&rdquo;], m = 5, n = 3</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The largest subset with at most 5 0&rsquo;s and 3 1&rsquo;s is {&ldquo;10&rdquo;, &ldquo;0001&rdquo;, &ldquo;1&rdquo;, &ldquo;0&rdquo;}, so the answer is 4. Other valid but smaller subsets include {&ldquo;0001&rdquo;, &ldquo;1&rdquo;} and {&ldquo;10&rdquo;, &ldquo;1&rdquo;, &ldquo;0&rdquo;}. {&ldquo;111001&rdquo;} is an invalid subset because it contains 4 1&rsquo;s, greater than the maximum of 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> strs = [&ldquo;10&rdquo;,&ldquo;0&rdquo;,&ldquo;1&rdquo;], m = 1, n = 1</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The largest subset is {&ldquo;0&rdquo;, &ldquo;1&rdquo;}, so the answer is 2.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= strs.length <= 600</code></li> <li><code>1 <= strs[i].length <= 100</code></li> <li><code>strs[i]</code> consists only of digits <code>'0'</code> and <code>'1'</code>.</li> <li><code>1 <= m, n <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • findMaxForm

      public int findMaxForm(String[] strs, int m, int n)