当前位置:网站首页>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号又要延长一周左右啦
边栏推荐
- 微信支付WxPayPubHelper v3版 回调xml为空的原因
- Cloud games | cloud computing drives the game industry into a "new era"
- How to design test cases
- 电商秒杀系统
- Wechat applet transmits parameters (data-) by clicking events
- QQmlApplicationEngine failed to load component qrc:/main. qml:-1 No such file or directory
- "More Ford, more China" saw through the clouds, and the orders of Changan Ford's flagship products exceeded 10000
- RIDE:获取图片base64
- 35 giant technology companies jointly form the meta universe standard Forum Organization
- CTFSHOW框架复现篇
猜你喜欢

How to use dataant to monitor Apache APIs IX

Spark - understand partitioner in one article

Redis' cache penetration, cache breakdown and cache avalanche

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

Kubevela 1.4: make application delivery safer, easier to use, and more transparent

Introduction to digital transformation solutions for enterprises going to sea

微信小程序中的数据双向绑定

Jmeter跨线程参数关联无需脚本

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

RIDE:获取图片base64
随机推荐
[Android, kotlin, tflite] mobile device integration depth learning light model tflite (image classification)
What are the contents and processes of software validation testing? How much does it cost to confirm the test report?
Fastjson V2 简单使用手册
【Android,Kotlin,TFLite】移动设备集成深度学习轻模型TFlite(图像分类篇)
Solve arm_ release_ ver of this libmali is ‘g2p0-01eac0‘,rk_ so_ Ver is' 4 ', libgl1 mesa dev will not be installed, and there are unsatisfied dependencies
How to open a stock account? Is it safe to open a mobile account
微信小程序中的数据双向绑定
Doker's container data volume
基金客户服务
Cloud games | cloud computing drives the game industry into a "new era"
d编译时计数
电商秒杀系统
How to mention hot fix and cherry pick
Zero sample and small sample learning
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
分享十万级TPS的IM即时通讯综合消息系统的架构
206页上海BIM技术应用与发展报告2021
理想中的接口自动化项目
Netease cloud sign in lottery? That year I could sign in for 365 days. No? Look.
Ctfshow permission maintenance