当前位置:网站首页>leetcode 416. Partition equal subset sum partition equal subset sum (medium)
leetcode 416. Partition equal subset sum partition equal subset sum (medium)
2022-06-29 22:32:00 【InfoQ】
One 、 The main idea of the topic
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
public class Solution {
public boolean canPartition(int[] nums) {
// Array sum
int sum = Arrays.stream(nums).sum();
// scene 1: And are odd and cannot be divided equally
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];
}
}
Four 、 Summary notes
- 2022/6/29 expect 7.5 Number
边栏推荐
- If you master these 28 charts, you will no longer be afraid to be asked about TCP knowledge during the interview
- 从零实现深度学习框架——LSTM从理论到实战【理论】
- This time, I will talk about technology and life
- Graduation summary of construction practice camp
- 为什么要同时重写hashcode和equals方法之简单理解
- mysql备份数据库linux
- Nacos-配置中心基本使用
- Hezhou air32f103cbt6 development board hands-on Report
- Daily mathematics serial 54: February 23
- 细说GaussDB(DWS)复杂多样的资源负载管理手段
猜你喜欢

Huawei's software testing director with 7 years' experience, several suggestions for all students who want to switch to software testing

从零实现深度学习框架——RNN从理论到实战【实战】

ASP dynamically creates table table

Daily question brushing record (VIII)
![Realizing deep learning framework from zero -- LSTM from theory to practice [theory]](/img/ac/164140eff1a6518d49ce25599d9c7b.png)
Realizing deep learning framework from zero -- LSTM from theory to practice [theory]

从零实现深度学习框架——LSTM从理论到实战【理论】

文件操作的底层原理(文件描述符与缓冲区)

5-1系统漏洞扫描

What are the software testing methods and technical knowledge points?

MySQL backup and restore
随机推荐
关于深度学习的概念理解(笔记)
从第三次技术革命看企业应用三大开发趋势
Underlying principles of file operations (file descriptors and buffers)
qt5.14.2连接ubuntu20.04的mysql数据库出错
Can cdc2.2.1 listen to multiple PgSQL libraries at the same time?
Optional类的高级使用
static关键字续、继承、重写、多态
Guangzhou launched a campaign to promote the safety of bottled gas and popularized the knowledge of gas safety
MySQL 锁常见知识点&面试题总结
mysql备份数据库linux
Three development trends of enterprise application viewed from the third technological revolution
5-1系統漏洞掃描
Can the flick CDC be used for incremental synchronization from Oracle to MySQL
Detailed description of gaussdb (DWS) complex and diverse resource load management methods
中国数据库崛起,阿里云李飞飞:中国云数据库多种主流技术创新已领先国外
Live broadcast platform development, enter the visual area to execute animation, dynamic effects and add style class names
[proteus simulation] digital tube display of stepping motor speed
Analyze apache SH script
MySQL lock common knowledge points & summary of interview questions
Detailed explanation of MySQL and mvcc and the difference between RC and RR for snapshot reading