当前位置:网站首页>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号又要延长一周左右啦
边栏推荐
- During telecommuting, the project team punched in the wechat group | solicited papers from the community
- 【Android,Kotlin,TFLite】移动设备集成深度学习轻模型TFlite(图像分类篇)
- KubeVela 1.4:让应用交付更安全、上手更简单、过程更透明
- Redis' cache penetration, cache breakdown and cache avalanche
- pytorch 的Conv2d的详细解释
- 微信小程序通过点击事件传参(data-)
- Lombok
- Meet the StreamNative | 杨子棵:是什么让我放弃了大厂 Offer
- MIT博士论文 | 优化理论与机器学习实践
- In 2022, the latest JCR officially released the list of the latest global impact factors (top 600)
猜你喜欢

Doker的容器数据卷
![[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)

多线程经典案例

Solution to the conflict between unique index and logical deletion

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

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

RIDE:获取图片base64

206页上海BIM技术应用与发展报告2021

shell 同时执行多任务下载视频

在线客服系统代码_h5客服_对接公众号_支持APP_支持多语言
随机推荐
5G智慧建筑解决方案2021
Prospects of world digitalization and machine intelligence in the next decade
Cesiumjs 2022 ^ source code interpretation [6] - new architecture of modelempirical
Redis' cache penetration, cache breakdown and cache avalanche
机器学习编译入门课程学习笔记第二讲 张量程序抽象
Understand target detection in one article: r-cnn, fast r-cnn, fast r-cnn, Yolo, SSD "suggestions collection"
AtCoder Beginner Contest 257
Wechat applet transmits parameters (data-) by clicking events
Redis' transaction and locking mechanism
云游戏| 云计算推动游戏行业进入“新纪元”
"More Ford, more China" saw through the clouds, and the orders of Changan Ford's flagship products exceeded 10000
35家巨头科技公司联合组成元宇宙标准论坛组织
Classic case of multithreading
Qt笔记(七十四)之QLineEdit指定输入类型
Sm2246en+ SanDisk 15131
Asynchronous transition scenario - generator
206页上海BIM技术应用与发展报告2021
Fund managers' corporate governance and risk management
Meet the streamnational | yangzike: what made me give up Dachang offer
未来十年世界数字化与机器智能展望