当前位置:网站首页>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
边栏推荐
- [Android, kotlin, tflite] mobile device integration deep learning light model tflite (object detection)
- 企业出海数字化转型解决方案介绍
- Deployment of microservices based on kubernetes platform
- 基金管理人公司治理和风险管理
- CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
- 1175. 质数排列 / 剑指 Offer II 104. 排列的数目
- Warmup preheating learning rate "suggestions collection"
- Braces on the left of latex braces in latex multiline formula
- Swift 5.0 - creation and use of swift framework
- Ctfshow permission maintenance
猜你喜欢

In depth analysis of Apache bookkeeper series: Part 4 - back pressure

KubeVela 1.4:让应用交付更安全、上手更简单、过程更透明

在线客服聊天系统源码_美观强大golang内核开发_二进制运行傻瓜式安装_附搭建教程...

什么是SRM系统,如何规范公司内部采购流程

QQmlApplicationEngine failed to load component qrc:/main. qml:-1 No such file or directory

Redis' transaction and locking mechanism

Fastjson V2 简单使用手册
![[Android, kotlin, tflite] mobile device integration deep learning light model tflite (object detection)](/img/7e/3e6ebfb90a82249d934296a041ba21.png)
[Android, kotlin, tflite] mobile device integration deep learning light model tflite (object detection)

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

Zero sample and small sample learning
随机推荐
基金销售行为规范及信息管理
Fastjson V2 simple user manual
Online customer service system code_ H5 customer service_ Docking with official account_ Support app_ Support for multiple languages
CTFSHOW框架复现篇
C language array interception, C string by array interception method (c/s)
Maxpool2d explanation -- Application in arrays and images
Strictly minor spanning tree
Introduction to machine learning compilation course learning notes lesson 2 tensor program abstraction
leetcode 474. Ones and Zeroes 一和零(中等)
Fund clients and sales agencies
Jmeter跨线程参数关联无需脚本
如何使用 DataAnt 监控 Apache APISIX
pytorch 的Conv2d的详细解释
During telecommuting, the project team punched in the wechat group | solicited papers from the community
5G智慧建筑解决方案2021
[golang] golang实现截取字符串函数SubStr
How to distinguish between platform security and online hype? What are the stop loss techniques for online speculation?
Qt笔记(七十四)之QLineEdit指定输入类型
How to mention hot fix and cherry pick
What does project management really manage?