当前位置:网站首页>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号又要延长一周左右啦
边栏推荐
- CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
- How cloud computing can protect online education in the post epidemic Era
- How to use dataant to monitor Apache APIs IX
- Doker的容器数据卷
- DNS server setup, forwarding, master-slave configuration
- 35家巨头科技公司联合组成元宇宙标准论坛组织
- Smart streetlights | cloud computing lights up the "spark" of smart cities
- 智慧路灯| 云计算点亮智慧城市的“星星之火”
- 如何区分平台安全和网上炒作?网络投机有哪些止损技巧?
- 一次革命、两股力量、三大环节:《工业能效提升行动计划》背后的“减碳”路线图
猜你喜欢

Fastjson V2 simple user manual

【Android,Kotlin,TFLite】移动设备集成深度学习轻模型TFlite(物体检测篇)

During telecommuting, the project team punched in the wechat group | solicited papers from the community

5G智慧建筑解决方案2021

Redis的缓存穿透、缓存击穿和缓存雪崩

Redis - 01 cache: how to use read cache to improve system performance?

项目管理到底管的是什么?

Ideal interface automation project

Shell multitasking to download video at the same time

Redis' transaction and locking mechanism
随机推荐
Fund clients and sales agencies
Two way data binding in wechat applet
Ctfshow permission maintenance
一次革命、两股力量、三大环节:《工业能效提升行动计划》背后的“减碳”路线图
How to use dataant to monitor Apache APIs IX
What is flush software? In addition, is it safe to open an account online now?
10 airbags are equipped as standard, and Chery arizer 8 has no dead corner for safety protection
shell 同时执行多任务下载视频
ESP8266 成为客户端和服务器
Fund sales code of conduct and information management
Zero sample and small sample learning
Redis的缓存穿透、缓存击穿和缓存雪崩
shell 同时执行多任务下载视频
机器学习编译入门课程学习笔记第二讲 张量程序抽象
In depth analysis of Apache bookkeeper series: Part 4 - back pressure
HP notebook disable touchpad after mouse is inserted
35 giant technology companies jointly form the meta universe standard Forum Organization
Asynchronous transition scenario - generator
图纸加密如何保障我们的核心图纸安全
异步过渡方案—Generator