当前位置:网站首页>leetcode 416. Partition Equal Subset Sum 分割等和子集(中等)
leetcode 416. Partition Equal Subset Sum 分割等和子集(中等)
2022-06-29 22:08:00 【InfoQ】
一、题目大意
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public boolean canPartition(int[] nums) {
// 数组求和
int sum = Arrays.stream(nums).sum();
// 场景1:和为奇数不能均分
if (sum % 2 == 1) {
return false;
}
int target = sum / 2;
int n = nums.length;
boolean[][] dp = new boolean[n + 1][target + 1];
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= target; j++) {
if (j < nums[i - 1]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = dp[i - 1][j] || dp[i - 1][j - nums[i - 1]];
}
}
}
return dp[n][target];
}
}
四、总结小记
- 2022/6/29 期待7.5号
边栏推荐
- Daily question brushing record (VIII)
- ASP. Net cross page submission (button control page redirection)
- 客户端可以连接远程mysql
- [force deduction 10 days SQL introduction] day7+8 calculation function
- Grep工具
- 尚硅谷实时数据仓库项目(阿里云实时数仓)
- Spark cluster installation
- Divide the bonus pool of 10million + million yuan, and empower developers in the 2022 shengteng AI innovation competition
- 生产环境AIX小机报错B6267342问题处理
- What are the software testing methods and technical knowledge points?
猜你喜欢

Detailed description of gaussdb (DWS) complex and diverse resource load management methods

The logic behind the three whys encountered in technical communication

Low code, end-to-end, one hour to build IOT sample scenarios, and the sound network released lingfalcon Internet of things cloud platform

cout 不明确问题

The soft youth under the blessing of devcloud makes education "smart" in the cloud

这次跟大家聊聊技术,也聊聊人生

Huawei cloud AOM version 2.0 release

26 years old, 0 basic career change software test, from 3K to 16K monthly salary, a super complete learning guide compiled by me

ASP using panel to realize simple registration page

科大讯飞 AI 学习机暑期新品发布会 AI + 教育深度结合再创产品新高度
随机推荐
How to use filters in jfinal to monitor Druid for SQL execution?
ASP dynamically creates table table
英语没学好到底能不能做coder,别再纠结了先学起来
掌握这28张图,面试再也不怕被问TCP知识了
The solution to the "undefined symbol: \u cxa\throw\bad\array\new\u length, version qt\u 5" error reported by the Kirin system startup application
Dynamic planning learning (continuous update)
Can the flick CDC be used for incremental synchronization from Oracle to MySQL
The inadvertently discovered [tidb cache table] can solve the read / write hotspot problem
Which securities to choose for securities account opening? In addition, is it safe to open an account online now?
leetcode:91. 解码方法【dfs + 记忆化】
If I am in Zhuhai, where can I open an account? Is it safe to open an account online?
Graduation summary of construction practice camp
Datakit acts as an API server for local data acquisition
Live broadcast platform development, enter the visual area to execute animation, dynamic effects and add style class names
Simple analysis of wieshark packet capturing MySQL protocol
Automatic reply of wechat bulletin number intelligent reply with Turing robot
Structure the fifth operation of the actual camp module
细说GaussDB(DWS)复杂多样的资源负载管理手段
阶段性总结与思考
Simple understanding of why to rewrite hashcode and equals methods at the same time