当前位置:网站首页>leetcode 474. Ones and zeroes (medium)
leetcode 474. Ones and zeroes (medium)
2022-06-30 23:19:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= strs.length <= 600
- 1 <= strs[i].length <= 100
- strs[i] Only by '0' and '1' form
- 1 <= m, n <= 100
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
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];
}
/**
* In the calculation string 0 and 1 The number of
*/
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};
}
}
Four 、 Summary notes
- 2022/6/30 7.5 It will be extended for another week or so
边栏推荐
- 76页智慧物流园区综合解决方案2022(附下载)
- 云游戏| 云计算推动游戏行业进入“新纪元”
- 电商秒杀系统
- HP 惠普笔记本电脑 禁用触摸板 在插入鼠标后
- Advanced mathematical modeling
- Swift 5.0 - creation and use of swift framework
- Wechat applet transmits parameters (data-) by clicking events
- ESP8266 成为客户端和服务器
- CNN classic network model details -lenet-5 (pytorch Implementation)
- Maxpool2d explanation -- Application in arrays and images
猜你喜欢
如何使用 DataAnt 监控 Apache APISIX
What does the &?
ESP8266 成为客户端和服务器
什么是SRM系统,如何规范公司内部采购流程
Esp8266 becomes client and server
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
Two dots on the top of the latex letter
女朋友说:你要搞懂了MySQL三大日志,我就让你嘿嘿嘿!
HP notebook disable touchpad after mouse is inserted
远程办公期间,项目小组微信群打卡 | 社区征文
随机推荐
Redis' transaction and locking mechanism
What are the contents and processes of software validation testing? How much does it cost to confirm the test report?
零样本和少样本学习
Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical
Shell multitasking to download video at the same time
Youfu network hybrid cloud accelerates enterprise digital transformation and upgrading
Redis的事务和锁机制
Esp8266 becomes client and server
CTFSHOW框架复现篇
Advanced mathematical modeling
Ctfshow permission maintenance
CNN classic network model details -lenet-5 (pytorch Implementation)
DNS server setup, forwarding, master-slave configuration
Detailed explanation of conv2d of pytorch
6-1 exploit -ftp exploit
有孚网络混合云,加速企业数字化转型升级
Classic case of multithreading
Wechat applet transmits parameters (data-) by clicking events
1175. 質數排列 / 劍指 Offer II 104. 排列的數目
一次革命、两股力量、三大环节:《工业能效提升行动计划》背后的“减碳”路线图