We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b2c2b1a + c1d99b1 commit eccb4c5Copy full SHA for eccb4c5
474. Ones and Zeroes
@@ -0,0 +1,18 @@
1
+class Solution {
2
+public:
3
+ int findMaxForm(vector<string>& strs, int m, int n) {
4
+ vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
5
+
6
+ for (string& s : strs) {
7
+ int zeros = count(s.begin(), s.end(), '0');
8
+ int ones = s.size() - zeros;
9
+ for (int i = m; i >= zeros; --i) {
10
+ for (int j = n; j >= ones; --j) {
11
+ dp[i][j] = max(dp[i][j], dp[i - zeros][j - ones] + 1);
12
+ }
13
14
15
16
+ return dp[m][n];
17
18
+};
0 commit comments