当前位置:网站首页>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
边栏推荐
- 有孚网络混合云,加速企业数字化转型升级
- [无线通信基础-13]:图解移动通信技术与应用发展-1-概述
- Deployment of microservices based on kubernetes platform
- Sm2246en+ SanDisk 15131
- What does the &?
- Code de conduite pour la vente de fonds et la gestion de l'information
- Architecture of IM integrated messaging system sharing 100000 TPS
- [Android, kotlin, tflite] mobile device integration deep learning light model tflite (object detection)
- During telecommuting, the project team punched in the wechat group | solicited papers from the community
- Flitter - sort list sort
猜你喜欢

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

一次革命、两股力量、三大环节:《工业能效提升行动计划》背后的“减碳”路线图

How to use dataant to monitor Apache APIs IX

76页智慧物流园区综合解决方案2022(附下载)

HP 惠普笔记本电脑 禁用触摸板 在插入鼠标后

Ms17-010 Eternal Blue vulnerability of MSF

远程办公期间,项目小组微信群打卡 | 社区征文

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

206 page Shanghai BIM Technology Application and development report 2021

In depth analysis of Apache bookkeeper series: Part 4 - back pressure
随机推荐
Swift5.0 ----Swift FrameWork的创建及使用
Fund customer service
股票开户要如何办理呢?办理手机开户安全吗
composer
76页智慧物流园区综合解决方案2022(附下载)
8253A寄存器浅析
As the public cloud market enters the deep water, can the calm Amazon cloud still sit still?
shell 同时执行多任务下载视频
Braces on the left of latex braces in latex multiline formula
5g smart building solution 2021
D compile time count
1175. 质数排列 / 剑指 Offer II 104. 排列的数目
Cloud games | cloud computing drives the game industry into a "new era"
What does the &?
HP notebook disable touchpad after mouse is inserted
Schéma de transition asynchrone - générateur
Prospects of world digitalization and machine intelligence in the next decade
The superficial understanding of the industrial Internet finally brought the development of the industrial Internet into the strange circle of the consumer Internet
[golang] golang实现截取字符串函数SubStr
Redis - 01 cache: how to use read cache to improve system performance?