当前位置:网站首页>leetcode 474. Ones and Zeroes 一和零(中等)
leetcode 474. Ones and Zeroes 一和零(中等)
2022-06-30 23:12:00 【InfoQ】
一、题目大意
- 1 <= strs.length <= 600
- 1 <= strs[i].length <= 100
- strs[i] 仅由 '0' 和 '1' 组成
- 1 <= m, n <= 100
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int findMaxForm(String[] strs, int m, int n) {
int[][] dp = new int[m + 1][n + 1];
for (String str : strs) {
int[] countArr = count(str);
int count0 = countArr[0];
int count1 = countArr[1];
for (int i = m; i>= count0; i--) {
for (int j = n; j>= count1; j--) {
dp[i][j] = Math.max(dp[i][j], 1 + dp[i-count0][j-count1]);
}
}
}
return dp[m][n];
}
/**
* 计算字符串中0和1的数量
*/
int[] count(String s) {
int count0 = s.length();
int count1 = 0;
for (char c : s.toCharArray()) {
if ('1' == c) {
count1++;
count0--;
}
}
return new int[]{count0, count1};
}
}
四、总结小记
- 2022/6/30 7.5号又要延长一周左右啦
边栏推荐
- Solve arm_ release_ ver of this libmali is ‘g2p0-01eac0‘,rk_ so_ Ver is' 4 ', libgl1 mesa dev will not be installed, and there are unsatisfied dependencies
- 在线客服系统代码_h5客服_对接公众号_支持APP_支持多语言
- Achieve secure data sharing among multiple parties and solve the problem of asymmetric information in Inclusive Finance
- 有孚网络混合云,加速企业数字化转型升级
- CNN classic network model details -lenet-5 (pytorch Implementation)
- Prospects of world digitalization and machine intelligence in the next decade
- What does the software test report contain? How to obtain high quality software test reports?
- 基金銷售行為規範及信息管理
- How cloud computing can protect online education in the post epidemic Era
- E-commerce seckill system
猜你喜欢

Zero sample and small sample learning

Redis' cache penetration, cache breakdown and cache avalanche

Redis' transaction and locking mechanism

分享十万级TPS的IM即时通讯综合消息系统的架构

"Paddle + camera" has become a "prefabricated dish" in the AI world, and it is easier to implement industrial AI quality inspection

微信小程序中的数据双向绑定

多線程經典案例

机器学习编译入门课程学习笔记第二讲 张量程序抽象

Deployment of microservices based on kubernetes platform

Doker's container data volume
随机推荐
In depth analysis of Apache bookkeeper series: Part 4 - back pressure
Prospects of world digitalization and machine intelligence in the next decade
During telecommuting, the project team punched in the wechat group | solicited papers from the community
Doker's container data volume
Redis' transaction and locking mechanism
Redis' cache penetration, cache breakdown and cache avalanche
How to use dataant to monitor Apache APIs IX
Shell multitasking to download video at the same time
Understand target detection in one article: r-cnn, fast r-cnn, fast r-cnn, Yolo, SSD "suggestions collection"
AtCoder Beginner Contest 255
Redis - 01 缓存:如何利用读缓存提高系统性能?
Lombok
理想中的接口自动化项目
Two dots on the top of the latex letter
在线客服聊天系统源码_美观强大golang内核开发_二进制运行傻瓜式安装_附搭建教程...
Ctfshow permission maintenance
Flitter - sort list sort
HP notebook disable touchpad after mouse is inserted
E-commerce seckill system
CTFSHOW框架复现篇