474. Ones and Zeroes Medium
1/**
2 * [474] Ones and Zeroes
3 *
4 * You are given an array of binary strings strs and two integers m and n.
5 * Return the size of the largest subset of strs such that there are at most m 0's and n 1's in the subset.
6 * A set x is a subset of a set y if all elements of x are also elements of y.
7 *
8 * Example 1:
9 *
10 * Input: strs = ["10","0001","111001","1","0"], m = 5, n = 3
11 * Output: 4
12 * Explanation: The largest subset with at most 5 0's and 3 1's is {"10", "0001", "1", "0"}, so the answer is 4.
13 * Other valid but smaller subsets include {"0001", "1"} and {"10", "1", "0"}.
14 * {"111001"} is an invalid subset because it contains 4 1's, greater than the maximum of 3.
15 *
16 * Example 2:
17 *
18 * Input: strs = ["10","0","1"], m = 1, n = 1
19 * Output: 2
20 * Explanation: The largest subset is {"0", "1"}, so the answer is 2.
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= strs.length <= 600
26 * 1 <= strs[i].length <= 100
27 * strs[i] consists only of digits '0' and '1'.
28 * 1 <= m, n <= 100
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/ones-and-zeroes/
34// discuss: https://leetcode.com/problems/ones-and-zeroes/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn find_max_form(strs: Vec<String>, m: i32, n: i32) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_474() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.