Skip to content

Commit eccb4c5

Browse files
authored
Create 474. Ones and Zeroes (#931)
2 parents b2c2b1a + c1d99b1 commit eccb4c5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

474. Ones and Zeroes

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)