魔法师 (@Constanline) 在 Leetcode每日一题 —— 474. 一和零 中发帖
474. 一和零
思路
看完题目感觉像是典型的0、1背包,锁定动态规划。列方程的时候发现好像不对,这道题有两个容量,不过问题不大,都当做一个维度即可。
代码
public int findMaxForm(String[] strs, int m, int n) {
int[][] dp = new int[m + 1][n + 1];
int[] cnt = new int[2];
for (String str : strs) {
cnt[0] = cnt[1] = 0;
for (char c : str.toCharArray()) {
cnt[c - '0']++;
}
int zero = ...